Documentation ¶
Index ¶
- Variables
- func NewCreateHandler(l *slog.Logger, users Storer) http.Handler
- func NewLoginHandler(l *slog.Logger, users Retreiver) http.Handler
- func WriteUnauthorizedError(l *slog.Logger, w http.ResponseWriter, err error)
- type BcryptHash
- type Retreiver
- type SQLUserStore
- type Storer
- type User
- type UserStore
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidFields = errors.New("contains invalid fields") ErrWrongPassword = errors.New("wrong password") )
Functions ¶
func WriteUnauthorizedError ¶
func WriteUnauthorizedError(l *slog.Logger, w http.ResponseWriter, err error)
Types ¶
type BcryptHash ¶
type BcryptHash struct {
// contains filtered or unexported fields
}
func NewBcryptHash ¶
func NewBcryptHash(password string) (BcryptHash, error)
type Retreiver ¶
type Retreiver interface { // ByUsername returns the User given a username // it returns an ErrNotFound if user does not exists // includeWorkouts and includeExercises include // the user's workouts and workout exercises as well ByUsername(username string) (User, error) // Authenticate returns the user after checking the // credentials. It returns an ErrWrongPassword if // username/password pair doesn't match Authenticate(username string, password []byte) (User, error) }
Retreiver implementations can query data
type SQLUserStore ¶
type SQLUserStore struct {
*storage.SqliteDatastore
}
func (*SQLUserStore) Authenticate ¶
func (us *SQLUserStore) Authenticate(username string, password []byte) (User, error)
func (*SQLUserStore) ByUsername ¶
func (us *SQLUserStore) ByUsername(username string) (User, error)
type Storer ¶
type Storer interface { // New is responsible for validating the email and // encrypting the password before storing. A new userID will // be returned on success otherwise an error is thrown New(username string, email string, password []byte) (User, error) }
Storer allow for new users to be created
type User ¶
type User struct { Username string `json:"username"` Email string `json:"email"` Password []byte `json:"password"` }
User is a registered person that can login to the application. Password is the encrypted password.
type UserStore ¶
UserStore represents the user repository
func NewSQLUserStore ¶
func NewSQLUserStore(ds *storage.SqliteDatastore) UserStore
Click to show internal directories.
Click to hide internal directories.