Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Settings ¶
type Settings struct { UserRepo UserRepository Resolver *jwtresolver.JWTResolver Validator *validator.Validator }
Settings used to create UserController. Settings must be provided to New function. All fields are required and cant be nil.
type UserController ¶
type UserController struct {
// contains filtered or unexported fields
}
UserController used to register and login users. Must be created with New function.
func New ¶
func New(settings Settings) *UserController
New creates new UserController. Returns pointer to UserController. Accepts Settings as argument.
func (*UserController) Login ¶
func (c *UserController) Login( ctx context.Context, credentials models.Credentials, ) (string, error)
Login returns JWT token with user ID or error if login failed. Must be called with valid credentials with non-empty login and password.
func (*UserController) Register ¶
func (c *UserController) Register( ctx context.Context, credentials models.Credentials, ) (string, error)
Register registers new user and returns JWT token with user ID. Returns error if registration failed. Must be called with valid credentials with non-empty login, password and token.
type UserRepository ¶
type UserRepository interface { // AddUser add user to repository. AddUser(ctx context.Context, login, passHash string) (uuid.UUID, error) // GetUserByLogin get user from repository. GetUserByLogin(ctx context.Context, login string) (models.User, error) }
UserRepository used to get user by login and add user.