Documentation ¶
Index ¶
- Variables
- type AuthProvider
- type Formatter
- type Interactor
- func (i Interactor) AuthCheck(w http.ResponseWriter, r *http.Request) (*models.User, error)
- func (i Interactor) FormatSelf(user *models.User) interface{}
- func (i Interactor) FormatService(svc *models.Service) interface{}
- func (i Interactor) FormatServices(svx []*models.Service) interface{}
- func (i Interactor) FormatTimedResponses(tr []*models.TimedResponse) interface{}
- func (i Interactor) GetServiceByID(user *models.User, id string) (*models.Service, error)
- func (i Interactor) GetServices(user *models.User) ([]*models.Service, error)
- func (i Interactor) GetTimedResponseRange(user *models.User, id string, from, to time.Time) ([]*models.TimedResponse, error)
- func (i Interactor) GetTimedResponsesByServiceID(user *models.User, id string, limit int, reverse bool) ([]*models.TimedResponse, error)
- func (i Interactor) Login(email, password string) (*models.TokenPair, *http.Cookie, error)
- func (i Interactor) Logout() *http.Cookie
- func (i Interactor) NewService(user *models.User, name, description, url string) (*models.Service, error)
- func (i Interactor) Refresh(token string) (*models.TokenPair, error)
- func (i Interactor) Register(email, password string) error
- type LogicHandler
- type Scheduler
- type StorageProvider
Constants ¶
This section is empty.
Variables ¶
var ErrBearerTokenNotFound = errors.New("token not found")
ErrBearerTokenNotFound is returned when the bearer token can't be found in the http request
var ErrCookieFormat = errors.New("wrong cookie format")
ErrCookieFormat is returned when the cookie value can't be unmarshalled
var ErrCookieNotFound = errors.New("cookie not found")
ErrCookieNotFound is returned when the cookie can't be found
var ErrInvalidCredentials = errors.New("invalid credentials")
ErrInvalidCredentials is returned when invalid credentials are provided
var ErrInvalidJWT = errors.New("invalid jwt")
ErrInvalidJWT is returned when the JWT isn't valid (expired, unsigned, etc.)
var ErrJWT = errors.New("jwt error")
ErrJWT is a JWT error
var ErrNoAuthenticationFound = errors.New("no authentication found")
ErrNoAuthenticationFound is returned when neither the bearer token or the cookie can be found
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when an element isn't found
var ErrPermission = errors.New("permission error")
ErrPermission is returned when a permission error occurs
Functions ¶
This section is empty.
Types ¶
type AuthProvider ¶
type AuthProvider interface { GenerateTokenPair(user *models.User) (*models.TokenPair, error) CheckToken(token string) (*jwt.RegisteredClaims, error) ValidateBearerToken(r *http.Request) (*jwt.RegisteredClaims, error) ValidateCookie(r *http.Request) (*jwt.RegisteredClaims, bool, error) GenerateCookie(u *models.User, tp *models.TokenPair) (*http.Cookie, error) DropAccessCookie() *http.Cookie }
AuthProvider is a simple auth provider interface
type Formatter ¶
type Formatter interface { Self(user *models.User) interface{} Service(svc *models.Service) interface{} Services(svx []*models.Service) interface{} TimedResponses(tr []*models.TimedResponse) interface{} }
Formatter is a simple interface in charge of formatting our documents
type Interactor ¶
type Interactor struct { Store StorageProvider Auth AuthProvider Formatter Formatter Logger *zerolog.Logger Scheduler Scheduler }
Interactor contains the dependencies of the service
func (Interactor) AuthCheck ¶
func (i Interactor) AuthCheck(w http.ResponseWriter, r *http.Request) (*models.User, error)
AuthCheck extracts the JWT token and the associated user from the incoming HTTP request
func (Interactor) FormatSelf ¶
func (i Interactor) FormatSelf(user *models.User) interface{}
func (Interactor) FormatService ¶
func (i Interactor) FormatService(svc *models.Service) interface{}
func (Interactor) FormatServices ¶
func (i Interactor) FormatServices(svx []*models.Service) interface{}
func (Interactor) FormatTimedResponses ¶
func (i Interactor) FormatTimedResponses(tr []*models.TimedResponse) interface{}
func (Interactor) GetServiceByID ¶
func (Interactor) GetServices ¶
func (Interactor) GetTimedResponseRange ¶
func (i Interactor) GetTimedResponseRange(user *models.User, id string, from, to time.Time) ([]*models.TimedResponse, error)
func (Interactor) GetTimedResponsesByServiceID ¶
func (i Interactor) GetTimedResponsesByServiceID(user *models.User, id string, limit int, reverse bool) ([]*models.TimedResponse, error)
func (Interactor) Login ¶
Login allows users to login and will return an access token on successful login
func (Interactor) Logout ¶
func (i Interactor) Logout() *http.Cookie
func (Interactor) NewService ¶
func (Interactor) Register ¶
func (i Interactor) Register(email, password string) error
type LogicHandler ¶
type LogicHandler interface { Register(email, password string) error Login(email, password string) (*models.TokenPair, *http.Cookie, error) Refresh(token string) (*models.TokenPair, error) Logout() *http.Cookie AuthCheck(w http.ResponseWriter, r *http.Request) (*models.User, error) NewService(user *models.User, name, description, url string) (*models.Service, error) FormatSelf(user *models.User) interface{} FormatService(svc *models.Service) interface{} FormatServices(svx []*models.Service) interface{} FormatTimedResponses(tr []*models.TimedResponse) interface{} GetServiceByID(user *models.User, id string) (*models.Service, error) GetServices(user *models.User) ([]*models.Service, error) GetTimedResponsesByServiceID(user *models.User, id string, limit int, reverse bool) ([]*models.TimedResponse, error) GetTimedResponseRange(user *models.User, id string, from, to time.Time) ([]*models.TimedResponse, error) }
LogicHandler is the interface that must implement the struct holding the usecases. The interactor struct must implement this interface. This interface is the main entrypoint for the router.
func NewInteractor ¶
func NewInteractor(s StorageProvider, a AuthProvider, f Formatter, l *zerolog.Logger, sch Scheduler) LogicHandler
NewInteractor will return a new Interactor struct with all the required dependecies injected. This interactor implements the LogicHandler interface and thus should be provided to the router.
type StorageProvider ¶
type StorageProvider interface { SaveService(user *models.User, svc *models.Service) error SaveRawService(svc *models.Service) error SaveUser(usr *models.User) error GetUserByEmail(email string) (*models.User, error) GetUserByID(id string) (*models.User, error) GetTimedResponses(svc *models.Service, limit int, reverse bool) ([]*models.TimedResponse, error) GetTimedResponseRange(svc *models.Service, from, to time.Time) ([]*models.TimedResponse, error) CountTimedResponses(svc *models.Service) (int, error) SaveTimedResponse(tr *models.TimedResponse) error GetAllServices() ([]*models.Service, error) GetServiceByID(id string) (*models.Service, error) GetServices(user *models.User) ([]*models.Service, error) }
StorageProvider is a storage interface