Versions in this module Expand all Collapse all v0 v0.0.2 Feb 25, 2024 Changes in this version + const ConfigKeyAPIBase + const ConfigKeyAPIEnabled + const ConfigKeyAPIName + const ConfigKeyAPIUsesDBs + var ErrAlreadyExists = errors.New("resource with same identifying information already exists") + var ErrBadArgument = errors.New("one or more of the arguments is invalid") + var ErrBadCredentials = errors.New("the supplied username/password combination is incorrect") + var ErrBodyUnmarshal = errors.New("malformed data in request") + var ErrDB = errors.New("an error occured with the DB") + var ErrDBConstraintViolation = errors.New("a uniqueness constraint was violated") + var ErrDBDecodingFailure = errors.New("field could not be decoded from DB storage format to model format") + var ErrDBNotFound = errors.New("the requested resource was not found") + var ErrNotFound = errors.New("the requested entity could not be found") + var ErrPermissions = errors.New("you don't have permission to do that") + func GetURLParam[E any](r *http.Request, key string, parse func(string) (E, error)) (val E, err error) + func ParseJSONRequest(req *http.Request, v interface{}) error + func PathParam(nameType string) string + func RedirectNoTrailingSlash(sp ServiceProvider) http.HandlerFunc + func RequireIDParam(r *http.Request) uuid.UUID + func TypedSlice[E any](key string, value interface{}) ([]E, error) + func UnPathParam(s string) string + type API interface + Authenticators func() map[string]Authenticator + Init func(bndl Bundle) error + Routes func(ServiceProvider) (router chi.Router, subpaths bool) + Shutdown func(ctx context.Context) error + type APIConfig interface + Common func() CommonConfig + FillDefaults func() APIConfig + Get func(key string) interface{} + Keys func() []string + Set func(key string, value interface{}) error + SetFromString func(key string, value string) error + Validate func() error + type AuthUser struct + Created time.Time + Email string + ID uuid.UUID + LastLogin time.Time + LastLogout time.Time + Modified time.Time + Password string + Role Role + Username string + type AuthUserRepo interface + Close func() error + Create func(context.Context, AuthUser) (AuthUser, error) + Delete func(context.Context, uuid.UUID) (AuthUser, error) + Get func(context.Context, uuid.UUID) (AuthUser, error) + GetAll func(context.Context) ([]AuthUser, error) + GetByUsername func(ctx context.Context, username string) (AuthUser, error) + Update func(context.Context, uuid.UUID, AuthUser) (AuthUser, error) + type AuthUserStore interface + AuthUsers func() AuthUserRepo + type Authenticator interface + Authenticate func(req *http.Request) (AuthUser, bool, error) + Service func() UserLoginService + UnauthDelay func() time.Duration + type Bundle struct + func NewBundle(api APIConfig, g Globals, log Logger, dbs map[string]Store) Bundle + func (bndl Bundle) APIBase() string + func (bndl Bundle) Base() string + func (bndl Bundle) DB(n int) Store + func (bndl Bundle) DBNamed(name string) Store + func (bndl Bundle) Enabled() bool + func (bndl Bundle) Get(key string) string + func (bndl Bundle) GetBool(key string) bool + func (bndl Bundle) GetBoolSlice(key string) []bool + func (bndl Bundle) GetByteSlice(key string) []byte + func (bndl Bundle) GetFloat(key string) float64 + func (bndl Bundle) GetFloatSlice(key string) []float64 + func (bndl Bundle) GetInt(key string) int + func (bndl Bundle) GetInt16(key string) int16 + func (bndl Bundle) GetInt32(key string) int32 + func (bndl Bundle) GetInt64(key string) int64 + func (bndl Bundle) GetInt8(key string) int8 + func (bndl Bundle) GetIntSlice(key string) []int + func (bndl Bundle) GetSlice(key string) []string + func (bndl Bundle) GetTime(key string) time.Time + func (bndl Bundle) GetUint(key string) uint + func (bndl Bundle) GetUint16(key string) uint16 + func (bndl Bundle) GetUint32(key string) uint32 + func (bndl Bundle) GetUint64(key string) uint64 + func (bndl Bundle) GetUint8(key string) uint8 + func (bndl Bundle) Has(key string) bool + func (bndl Bundle) Logger() Logger + func (bndl Bundle) Name() string + func (bndl Bundle) ServerAddress() string + func (bndl Bundle) ServerBase() string + func (bndl Bundle) ServerPort() int + func (bndl Bundle) UsesDBs() []string + func (bndl Bundle) WithDBs(dbs map[string]Store) Bundle + type CommonConfig struct + Base string + Enabled bool + Name string + UsesDBs []string + func (cc *CommonConfig) Common() CommonConfig + func (cc *CommonConfig) FillDefaults() APIConfig + func (cc *CommonConfig) Get(key string) interface{} + func (cc *CommonConfig) Keys() []string + func (cc *CommonConfig) Set(key string, value interface{}) error + func (cc *CommonConfig) SetFromString(key string, value string) error + func (cc *CommonConfig) Validate() error + type Component interface + API func() API + Config func() APIConfig + Name func() string + type Config struct + APIs map[string]APIConfig + DBs map[string]DatabaseConfig + Format Format + Globals Globals + Log LogConfig + func (cfg Config) FillDefaults() Config + func (cfg Config) Validate() error + type DBType string + const DatabaseInMemory + const DatabaseNone + const DatabaseOWDB + const DatabaseSQLite + func ParseDBType(s string) (DBType, error) + func (dbt DBType) String() string + type DatabaseConfig struct + Connector string + DataDir string + DataFile string + Type DBType + func ParseDBConnString(s string) (DatabaseConfig, error) + func (db DatabaseConfig) FillDefaults() DatabaseConfig + func (db DatabaseConfig) Validate() error + type EndpointFunc func(req *http.Request) Result + type Error struct + func NewError(msg string, causes ...error) Error + func WrapDBError(err error, msg ...any) Error + func WrapDBErrorf(err error, format string, a ...any) Error + func (e Error) Error() string + func (e Error) Is(target error) bool + func (e Error) Unwrap() []error + type ErrorResponse struct + Error string + Status int + type Format int + const JSON + const NoFormat + const YAML + func (f Format) Extensions() []string + func (f Format) String() string + type Globals struct + Address string + MainAuthProvider string + Port int + URIBase string + func (g Globals) FillDefaults() Globals + func (g Globals) Validate() error + type LogConfig struct + Enabled bool + File string + Provider LogProvider + func (g LogConfig) Validate() error + func (log LogConfig) FillDefaults() LogConfig + type LogProvider int + const Jellog + const NoLog + const StdLog + func ParseLogProvider(s string) (LogProvider, error) + func (p LogProvider) String() string + type Logger interface + Debug func(string) + DebugBreak func() + Debugf func(string, ...interface{}) + Error func(string) + ErrorBreak func() + Errorf func(string, ...interface{}) + Info func(string) + InfoBreak func() + Infof func(string, ...interface{}) + LogResult func(req *http.Request, r Result) + Trace func(string) + TraceBreak func() + Tracef func(string, ...interface{}) + Warn func(string) + WarnBreak func() + Warnf func(string, ...interface{}) + type Middleware func(next http.Handler) http.Handler + type Override struct + Authenticators []string + func CombineOverrides(overs []Override) Override + type RESTServer interface + Add func(name string, api API) error + Config func() Config + RoutesIndex func() string + ServeForever func() error + Shutdown func(ctx context.Context) error + type ResponseGenerator interface + BadRequest func(userMsg string, internalMsg ...interface{}) Result + Conflict func(userMsg string, internalMsg ...interface{}) Result + Created func(respObj interface{}, internalMsg ...interface{}) Result + Err func(status int, userMsg, internalMsg string, v ...interface{}) Result + Forbidden func(internalMsg ...interface{}) Result + InternalServerError func(internalMsg ...interface{}) Result + LogResponse func(req *http.Request, r Result) + Logger func() Logger + MethodNotAllowed func(req *http.Request, internalMsg ...interface{}) Result + NoContent func(internalMsg ...interface{}) Result + NotFound func(internalMsg ...interface{}) Result + OK func(respObj interface{}, internalMsg ...interface{}) Result + Redirection func(uri string) Result + Response func(status int, respObj interface{}, internalMsg string, v ...interface{}) Result + TextErr func(status int, userMsg, internalMsg string, v ...interface{}) Result + Unauthorized func(userMsg string, internalMsg ...interface{}) Result + type Result struct + InternalMsg string + IsErr bool + IsJSON bool + Redir string + Resp interface{} + Status int + func (r *Result) PrepareMarshaledResponse() error + func (r Result) WithHeader(name, val string) Result + func (r Result) WriteResponse(w http.ResponseWriter) + type Role int64 + const Admin + const Guest + const Normal + const Unverified + func ParseRole(s string) (Role, error) + func (r *Role) Scan(value interface{}) error + func (r Role) String() string + func (r Role) Value() (driver.Value, error) + type ServiceProvider interface + DontPanic func() Middleware + Endpoint func(ep EndpointFunc, overrides ...Override) http.HandlerFunc + GetLoggedInUser func(req *http.Request) (user AuthUser, loggedIn bool) + OptionalAuth func(authenticators ...string) Middleware + RequiredAuth func(authenticators ...string) Middleware + SelectAuthenticator func(authenticators ...string) Authenticator + type Store interface + Close func() error + type UserLoginService interface + CreateUser func(ctx context.Context, username, password, email string, role Role) (AuthUser, error) + DeleteUser func(ctx context.Context, id string) (AuthUser, error) + GetAllUsers func(ctx context.Context) ([]AuthUser, error) + GetUser func(ctx context.Context, id string) (AuthUser, error) + GetUserByUsername func(ctx context.Context, username string) (AuthUser, error) + Login func(ctx context.Context, username string, password string) (AuthUser, error) + Logout func(ctx context.Context, who uuid.UUID) (AuthUser, error) + UpdatePassword func(ctx context.Context, id, password string) (AuthUser, error) + UpdateUser func(ctx context.Context, curID, newID, username, email string, role Role) (AuthUser, error) v0.0.1 Feb 24, 2024