Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateJwtSecretKey() (key [secretKeyBits / 8]byte, err error)
- func GetWelcomeMessage(r *ConfigRepository) (msg string)
- func InitDefaultConfig(r *ConfigRepository) (err error)
- func Migrate(db *sql.DB) (err error)
- type ConfigRepository
- type PostgresConfigRepository
- func (p *PostgresConfigRepository) Get(key string) (value string, err error)
- func (p *PostgresConfigRepository) InitDefault() (err error)
- func (p *PostgresConfigRepository) Set(key string, value string) (err error)
- func (p *PostgresConfigRepository) SetIfNotExists(key string, value string) (err error)
- type PostgresUserRepository
- func (r *PostgresUserRepository) CreateUser(user *User) (err error)
- func (r *PostgresUserRepository) GetUserByCID(cid int) (user *User, err error)
- func (r *PostgresUserRepository) UpdateUser(user *User) (err error)
- func (r *PostgresUserRepository) VerifyPasswordHash(plaintext string, hash string) (ok bool)
- type Repositories
- type SQLiteConfigRepository
- type SQLiteUserRepository
- type User
- type UserRepository
Constants ¶
View Source
const ( ConfigJwtSecretKey = "JWT_SECRET_KEY" ConfigFsdServerHostname = "FSD_SERVER_HOSTNAME" ConfigFsdServerIdent = "FSD_SERVER_IDENT" ConfigFsdServerLocation = "FSD_SERVER_LOCATION" ConfigApiServerBaseURL = "API_SERVER_BASE_URL" ConfigWelcomeMessage = "WELCOME_MESSAGE" )
Variables ¶
View Source
var ErrConfigKeyNotFound = errors.New("config: key not found")
Functions ¶
func GenerateJwtSecretKey ¶
func GetWelcomeMessage ¶
func GetWelcomeMessage(r *ConfigRepository) (msg string)
GetWelcomeMessage returns any configured welcome message. Returns an empty string if no message is found.
func InitDefaultConfig ¶
func InitDefaultConfig(r *ConfigRepository) (err error)
Types ¶
type ConfigRepository ¶
type ConfigRepository interface { // Set sets a value for a given key Set(key string, value string) (err error) // SetIfNotExists sets a value for a given key if it does not already exist SetIfNotExists(key string, value string) (err error) // Get gets a value for a given key. // // Returns ErrConfigKeyNotFound if no key/value pair is found. Get(key string) (value string, err error) }
func NewConfigRepository ¶
func NewConfigRepository(db *sql.DB) (ConfigRepository, error)
NewConfigRepository creates a ConfigRepository based on the database driver
type PostgresConfigRepository ¶
type PostgresConfigRepository struct {
// contains filtered or unexported fields
}
func (*PostgresConfigRepository) Get ¶
func (p *PostgresConfigRepository) Get(key string) (value string, err error)
Get retrieves the value for the given key from the configuration. If the key does not exist, it returns ErrConfigKeyNotFound.
func (*PostgresConfigRepository) InitDefault ¶
func (p *PostgresConfigRepository) InitDefault() (err error)
InitDefault initializes the default configuration values.
func (*PostgresConfigRepository) Set ¶
func (p *PostgresConfigRepository) Set(key string, value string) (err error)
Set sets the value for the given key in the configuration. If the key already exists, it updates the value.
func (*PostgresConfigRepository) SetIfNotExists ¶
func (p *PostgresConfigRepository) SetIfNotExists(key string, value string) (err error)
type PostgresUserRepository ¶
type PostgresUserRepository struct {
// contains filtered or unexported fields
}
func (*PostgresUserRepository) CreateUser ¶
func (r *PostgresUserRepository) CreateUser(user *User) (err error)
func (*PostgresUserRepository) GetUserByCID ¶
func (r *PostgresUserRepository) GetUserByCID(cid int) (user *User, err error)
func (*PostgresUserRepository) UpdateUser ¶
func (r *PostgresUserRepository) UpdateUser(user *User) (err error)
func (*PostgresUserRepository) VerifyPasswordHash ¶
func (r *PostgresUserRepository) VerifyPasswordHash(plaintext string, hash string) (ok bool)
type Repositories ¶
type Repositories struct { UserRepo UserRepository ConfigRepo ConfigRepository }
Repositories bundles all repository interfaces
func NewRepositories ¶
func NewRepositories(db *sql.DB) (repositories *Repositories, err error)
NewRepositories creates a Repositories bundle with implementations for the given database
type SQLiteConfigRepository ¶
type SQLiteConfigRepository struct {
// contains filtered or unexported fields
}
func (*SQLiteConfigRepository) Get ¶
func (s *SQLiteConfigRepository) Get(key string) (value string, err error)
func (*SQLiteConfigRepository) Set ¶
func (s *SQLiteConfigRepository) Set(key string, value string) (err error)
func (*SQLiteConfigRepository) SetIfNotExists ¶
func (s *SQLiteConfigRepository) SetIfNotExists(key string, value string) (err error)
type SQLiteUserRepository ¶
type SQLiteUserRepository struct {
// contains filtered or unexported fields
}
func (*SQLiteUserRepository) CreateUser ¶
func (r *SQLiteUserRepository) CreateUser(user *User) (err error)
func (*SQLiteUserRepository) GetUserByCID ¶
func (r *SQLiteUserRepository) GetUserByCID(cid int) (user *User, err error)
func (*SQLiteUserRepository) UpdateUser ¶
func (r *SQLiteUserRepository) UpdateUser(user *User) (err error)
func (*SQLiteUserRepository) VerifyPasswordHash ¶
func (r *SQLiteUserRepository) VerifyPasswordHash(plaintext string, hash string) (ok bool)
type UserRepository ¶
type UserRepository interface { // CreateUser creates a new User record. // The CID value is automatically populated in the provided User struct. // // The provided password must be in plaintext. CreateUser(*User) (err error) // GetUserByCID retrieves a User record by CID. // // Returns sql.ErrNoRows when no rows are found. GetUserByCID(cid int) (*User, error) // UpdateUser updates a User record by CID. // // All fields must be provided except: // // 1. Password is only updated if a non-empty string is provided. UpdateUser(*User) error // VerifyPasswordHash verifies a User password hash. VerifyPasswordHash(plaintext string, hash string) (ok bool) }
func NewUserRepository ¶
func NewUserRepository(db *sql.DB) (UserRepository, error)
NewUserRepository creates a UserRepository based on the database driver
Click to show internal directories.
Click to hide internal directories.