Documentation
¶
Index ¶
- Constants
- func ErrFromResponse(response *http.Response) error
- func ErrToMap(err errorConverter) map[string]interface{}
- func SetupDatabase(config *DatabaseConfig) (*sql.DB, error)
- func TruncateDatabase(db *sql.DB) error
- func ValidatePassword(password string, passwordHash, alg string) error
- type AccessTokenCfg
- type AppConfig
- type ClientMock
- type ConstantError
- type DatabaseConfig
- type ExternalServiceError
- type ExternalServicesConfig
- type Guest
- type GuestService
- type HTTPClient
- type LifespanCfg
- type LoginRequest
- type LoginResponce
- type LoginService
- type RefreshTokenCfg
- type TokensCfg
- type TomlConfig
- type User
Constants ¶
View Source
const ( ErrNoTokenSpecified = ConstantError("no token specified") ErrInvalidToken = ConstantError("invalid token") ErrTokenExpired = ConstantError("token expired") ErrInvalidJson = ConstantError("invalid JSON") ErrTokenNotExists = ConstantError("token does not exist") ErrInvalidQuery = ConstantError("invalid query parameters") ErrInvalidPassword = ConstantError("invalid password") )
constant errors because i don't like sentinel errors
Variables ¶
This section is empty.
Functions ¶
func ErrFromResponse ¶
parse error from json {"error":"error"} or error string nil if error is not parsed Function does not close response body
func SetupDatabase ¶
func SetupDatabase(config *DatabaseConfig) (*sql.DB, error)
func TruncateDatabase ¶
func ValidatePassword ¶
Types ¶
type AccessTokenCfg ¶
type AccessTokenCfg struct { LifespanCfg Secret string `validate:"required"` }
type ClientMock ¶
type ClientMock struct { Engine *gin.Engine Recorder *httptest.ResponseRecorder }
func NewClientMock ¶
func NewClientMock() *ClientMock
type ConstantError ¶
type ConstantError string
func (ConstantError) Error ¶
func (e ConstantError) Error() string
type DatabaseConfig ¶
type DatabaseConfig struct { Driver string `validate:"required"` Host string `validate:"required"` User string `validate:"required"` Password string `validate:"required"` Name string `toml:"database" validate:"required"` Port string `validate:"required"` }
func (*DatabaseConfig) GetUrl ¶
func (c *DatabaseConfig) GetUrl() string
type ExternalServiceError ¶
I want to return the same status code and message as the external service
func NewExternalServiceError ¶
func NewExternalServiceError(status int) *ExternalServiceError
func (*ExternalServiceError) Error ¶
func (e *ExternalServiceError) Error() string
func (*ExternalServiceError) Is ¶
func (e *ExternalServiceError) Is(err error) bool
type ExternalServicesConfig ¶
type ExternalServicesConfig struct { Guest GuestService `validate:"required"` Login LoginService `validate:"required"` }
type Guest ¶
func RegisterGuest ¶
model.ExternalServiceError error returned if error is parsed from external service response
type GuestService ¶
type HTTPClient ¶
type HTTPClient interface { Post(url string, contentType string, body io.Reader) (*http.Response, error) Get(url string) (resp *http.Response, err error) }
Little interface so i can mock some requests
type LifespanCfg ¶
type LifespanCfg struct { LifespanMinute uint `toml:"lifespan_minute"` LifespanHour uint `toml:"lifespan_hour"` LifespanDay uint `toml:"lifespan_day"` // contains filtered or unexported fields }
func (*LifespanCfg) Lifespan ¶
func (c *LifespanCfg) Lifespan() time.Duration
Just calculates time.Now() + lifespan
type LoginRequest ¶
type LoginResponce ¶
type LoginService ¶
type RefreshTokenCfg ¶
type RefreshTokenCfg struct { LifespanCfg Secret string `validate:"required"` }
type TokensCfg ¶
type TokensCfg struct { Access AccessTokenCfg `validate:"required"` Refresh RefreshTokenCfg `validate:"required"` }
type TomlConfig ¶
type TomlConfig struct { App AppConfig `validate:"required"` Database DatabaseConfig `validate:"required"` Tokens TokensCfg `validate:"required"` Services ExternalServicesConfig `validate:"required"` }
func ParseConfig ¶
func ParseConfig(filename string) (*TomlConfig, error)
Parses and validates config
func (*TomlConfig) Validate ¶
func (*TomlConfig) Validate() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.