Documentation ¶
Index ¶
- Constants
- Variables
- func NewGRPCMailerClient(port string) (*grpcMailerClient, error)
- func NewHTTPHandler(service Service) http.Handler
- func NewHTTPMailerClient(mailerEndpoint string) (*httpMailerClient, error)
- func NewMongoClient(uri string, timeout int) (*mongo.Client, error)
- func NewServer(handler http.Handler, port string) *server
- func NewValidator() *validator
- type MailerClient
- type PasswordManager
- type Repository
- type Service
- type ServiceBuilder
- type ServiceOption
- type TokenClient
- type UserClaims
- type UserDocument
- type UserInfo
- type UserLoginInfo
- type UserRegistrationDocument
- type UserRegistrationInfo
- type Validator
Constants ¶
const ActivationPageLink string = "http://localhost:5173/activate?token="
Variables ¶
var ( ErrInvalidJWT = errors.New("invalid jwt") ErrInvalidJWTSignature = errors.New("invalid jwt signature") )
var ErrDuplicateUser = errors.New("user already exists")
var ErrInvalidEmail = errors.New("user with this email was not found")
var ErrInvalidPassword = errors.New("invalid password provided")
var ErrMissingEnvs = errors.New("service: missing environment variables")
used by helper functions in service
var ErrMissingField = errors.New("missing field is required")
var ErrUserNotActivated = errors.New("user has not activated their account")
var ErrUserNotFound = errors.New("user not found")
Functions ¶
func NewGRPCMailerClient ¶
func NewHTTPHandler ¶
func NewHTTPMailerClient ¶
func NewValidator ¶
func NewValidator() *validator
Types ¶
type MailerClient ¶
type MailerClient interface {
// contains filtered or unexported methods
}
MailerClient is used by Service to make http or grpc calls to other services
type PasswordManager ¶
type PasswordManager interface { GenerateHash(password string) (string, error) CompareHashWith(hashedPassword, password string) error }
func NewPasswordManager ¶
func NewPasswordManager(cost int) PasswordManager
type Repository ¶
type Repository interface {
// contains filtered or unexported methods
}
! I'm not sure where to convert a UserInfo type to a UserDocument type ! in the repository or service layer
func NewRepository ¶
func NewRepository(client *mongo.Client, database string) Repository
Create a new user repository with the mongo client and database name
type Service ¶
type Service interface {
// contains filtered or unexported methods
}
func NewService ¶
func NewService(repository Repository, opts ...ServiceOption) Service
type ServiceBuilder ¶
type ServiceBuilder interface { Repository(repository Repository) ServiceBuilder MailerClient(client MailerClient) ServiceBuilder TokenClient(token TokenClient) ServiceBuilder PasswordManager(passwordManager PasswordManager) ServiceBuilder Validator(validator Validator) ServiceBuilder Build() Service }
! ServiceBuilder may be deprecated in favour of the ! idiomatic functional options pattern. I'm going to ! keep this here until I refactor some of the tests. ! I also want to see how it stacks up to the fo pattern ! when I do more benchmarking and profiling.
func NewServiceBuilder ¶
func NewServiceBuilder() ServiceBuilder
type ServiceOption ¶
type ServiceOption func(s *service)
func WithMailerClient ¶
func WithMailerClient(m MailerClient) ServiceOption
func WithPasswordManager ¶
func WithPasswordManager(p PasswordManager) ServiceOption
func WithTokenClient ¶
func WithTokenClient(t TokenClient) ServiceOption
func WithValidator ¶
func WithValidator(v Validator) ServiceOption
type TokenClient ¶
type TokenClient interface { CreateActivationToken(ctx context.Context, userID string) (string, error) ValidateActivationToken(ctx context.Context, activationToken string) (string, error) }
func NewTokenClient ¶
func NewTokenClient(port string) (TokenClient, error)
type UserClaims ¶
type UserClaims struct { jwt.MapClaims UserID string }
type UserDocument ¶
type UserDocument struct { OID primitive.ObjectID `bson:"_id,omitempty"` FirstName string `bson:"firstName"` LastName string `bson:"lastName"` Email string `bson:"email"` HashedPassword string `bson:"hashedPassword"` Activated bool `bson:"activated"` CreatedAt *time.Time `bson:"createdAt"` UpdatedAt *time.Time `bson:"updatedAt"` }
UserDocument is used to be used by a mongo repository implementation to transfer user data
type UserInfo ¶
type UserInfo struct { ID string `json:"id"` FirstName string `json:"firstName"` LastName string `json:"lastName"` Email string `json:"email"` Password string `json:"-"` HashedPassword string `json:"-"` Activated bool `json:"-"` CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` Token string `json:"token"` }
UserInfo is sent out as a response
type UserLoginInfo ¶
UserLoginInfo stores request data for logging in a user
type UserRegistrationInfo ¶
type UserRegistrationInfo struct { FirstName string `json:"firstName"` LastName string `json:"lastName"` Email string `json:"email"` Password string `json:"password"` HashedPassword string `json:"-"` Activated bool `json:"activated"` CreatedAt *time.Time `json:"createdAt"` UpdatedAt *time.Time `json:"updatedAt"` }
UserRegistrationInfo stores request data for registering a new user
type Validator ¶
type Validator interface { Registration(u UserRegistrationInfo) error Login(u UserLoginInfo) error NonEmptyString(name, field string) error }