Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthFail error = errors.New("[API-Users]: authentication failure") ErrNotAllowedRequestMethod error = errors.New("[API-Users]: requst method is not allowed for this endpoint") ErrUserExisted error = errors.New("[API-Users]: user already existed") ErrEnvNotLoaded = errors.New("[JWT]: fail to load the env file") ErrPayloadParsing = errors.New("[JWT]: fail to parse payload") )
Functions ¶
This section is empty.
Types ¶
type AuthCtl ¶
type AuthCtl struct {
// contains filtered or unexported fields
}
AuthCtl is a struct that represents an authentication controller.
func NewAuthCtl ¶
func NewAuthCtl(name string, apikey string, jwtConfig *JWTConfig, ds map[string]DataPointExtended) *AuthCtl
NewAuthCtl sets: - the apikey to use to connect to SingPass API Service - the name assigned to this struct (for reference purpose)
func (*AuthCtl) Auth ¶
func (a *AuthCtl) Auth(w http.ResponseWriter, r *http.Request)
Auth executes the authentication flow using SingPass API Service.
func (*AuthCtl) Register ¶
func (a *AuthCtl) Register(w http.ResponseWriter, r *http.Request)
Register add a user into the users microservice and cache the user data point returned by the microservice into the in-memory cache.
func (*AuthCtl) VerifyToken ¶
func (a *AuthCtl) VerifyToken(w http.ResponseWriter, r *http.Request)
VerifyToken works in complement with the middleware that execute the token verification checks. When the request reach this endpint, it has a valid token. This endpoint will return the verified JSON response body.
type CRUD ¶
type CRUD interface { Create(w http.ResponseWriter, r *http.Request) GetAll(w http.ResponseWriter, r *http.Request) GetById(w http.ResponseWriter, r *http.Request) UpdateById(w http.ResponseWriter, r *http.Request) DeleteById(w http.ResponseWriter, r *http.Request) }
CRUD interface for controller that needs to implemt CRUD features.
type CRUDController ¶
type CRUDController struct { CRUD // contains filtered or unexported fields }
type DataPoint ¶
type DataPoint struct { UserID float64 `json:"id"` Phone string `json:"phone"` Name string `json:"name"` Points float64 `json:"points"` LastLogin string `json:"last_login"` }
DataPoint holds the user data.
type DataPointExtended ¶
type DataPointExtended struct { UserID float64 `json:"id"` Phone string `json:"phone"` Name string `json:"name"` Password string `json:"password"` Points float64 `json:"points"` LastLogin string `json:"last_login"` }
DataPointExtended holds the user data, with password hash included.
type MerchantCtl ¶
type MerchantCtl struct { CRUD // contains filtered or unexported fields }
UserCtl is a struct that represents a user controller.
func NewMerchantCtl ¶
func NewMerchantCtl(name string, apikey string, ds map[string]DataPointExtended) *MerchantCtl
func (*MerchantCtl) Create ¶
func (u *MerchantCtl) Create(w http.ResponseWriter, r *http.Request)
AddTransaction executes the flow to add a recyclable transaction and assocate it to a specific user.
type ResponseBody ¶
type ResponseBody struct { Ok bool `json:"ok"` Msg string `json:"msg"` Data map[string]interface{} `json:"data"` }
ResponseBody struct holds the response data returned by microservice.
type Transaction ¶
type Transaction struct { Item string `json:"item"` Phone string `json:"phone"` Points float64 `json:"points"` Weight float64 `json:"weight"` }
Transaction struct holds the transaction data.
type TransactionCtl ¶
type TransactionCtl struct {
// contains filtered or unexported fields
}
TransactCtl is a struct that represents a user controller.
func NewTransactionCtl ¶
func NewTransactionCtl(name string, apikey string, ds map[string]DataPointExtended) *TransactionCtl
func (*TransactionCtl) Create ¶
func (t *TransactionCtl) Create(w http.ResponseWriter, r *http.Request)
Create executes the flow to add a recyclable transaction and assocate it to a specific user.
type UserCtl ¶
type UserCtl struct { CRUD // contains filtered or unexported fields }
UserCtl is a struct that represents a user controller.
func NewUserCtl ¶
func NewUserCtl(name string, apikey string, ds map[string]DataPointExtended) *UserCtl
type VouchersCtl ¶
type VouchersCtl struct {
// contains filtered or unexported fields
}
TransactCtl is a struct that represents a user controller.
func NewVouchersCtl ¶
func NewVouchersCtl(name string, apikey string, ds map[string]DataPointExtended) *VouchersCtl
func (*VouchersCtl) Create ¶
func (t *VouchersCtl) Create(w http.ResponseWriter, r *http.Request)
Create executes the flow to add a recyclable transaction and assocate it to a specific user.