Documentation ¶
Index ¶
- Constants
- func AddRESTRoutes(r *gin.Engine)
- func BasicToken(r *http.Request) (token string, ok bool)
- func BearerAuthMiddleware() gin.HandlerFunc
- func BearerToken(r *http.Request) (token string, ok bool)
- func ChangeEmailPasswordHandler(typeString string, mapper datamapper.IChangeEmailPasswordMapper) func(c *gin.Context)
- func ClientAuthMiddleware() gin.HandlerFunc
- func ClientFromContext(r *http.Request) *models.Client
- func CreateHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func CreatedTimeRangeFromQueryString(values *url.Values) (*int, *int, error)
- func DeleteManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func DeleteOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func ExpFromContext(r *http.Request) float64
- func GetOptionByParsingURL(r *http.Request) (map[datamapper.URLParam]interface{}, error)
- func IDFromURLQueryString(c *gin.Context) (*datatypes.UUID, render.Renderer)
- func IatFromContext(r *http.Request) float64
- func JSONPatchesFromJSONBody(r *http.Request) ([]models.JSONIDPatch, render.Renderer)
- func LatestnFromQueryString(values *url.Values) *string
- func LimitAndOffsetFromQueryString(values *url.Values) (*int, *int, error)
- func ModelFromJSONBody(r *http.Request, typeString string, who models.Who) (models.IModel, render.Renderer)
- func ModelOrModelsFromJSONBody(r *http.Request, typeString string, who models.Who) ([]models.IModel, *bool, render.Renderer)
- func ModelsFromJSONBody(r *http.Request, typeString string, who models.Who) ([]models.IModel, render.Renderer)
- func NewErrBadRequest(err error) render.Renderer
- func NewErrClientNotAuthorized(err error) render.Renderer
- func NewErrCreate(err error) render.Renderer
- func NewErrDBError(err error) render.Renderer
- func NewErrDelete(err error) render.Renderer
- func NewErrGenJSON(err error) render.Renderer
- func NewErrGeneratingToken(err error) render.Renderer
- func NewErrInternalServerError(err error) render.Renderer
- func NewErrInvalidRefreshToken(err error) render.Renderer
- func NewErrLoginUser(err error) render.Renderer
- func NewErrNotFound(err error) render.Renderer
- func NewErrParsingJSON(err error) render.Renderer
- func NewErrPatch(err error) render.Renderer
- func NewErrPermissionDeniedForAPIEndpoint(err error) render.Renderer
- func NewErrQueryParameter(err error) render.Renderer
- func NewErrReadingBody(err error) render.Renderer
- func NewErrTokenInvalid(err error) render.Renderer
- func NewErrURLParameter(err error) render.Renderer
- func NewErrUpdate(err error) render.Renderer
- func NewErrValidation(err error) render.Renderer
- func OrderFromQueryString(values *url.Values) *string
- func OwnerIDFromContext(r *http.Request) *datatypes.UUID
- func PatchManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func PatchOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func ReadAllHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func ReadOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func RenderModel(w http.ResponseWriter, r *http.Request, typeString string, ...)
- func RenderModelSlice(w http.ResponseWriter, r *http.Request, typeString string, ...)
- func ScopeFromContext(r *http.Request) *string
- func Token(c *gin.Context)
- func TokenHoursFromContext(r *http.Request) *float64
- func UpdateManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func UpdateOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
- func UserLoginHandler(typeString string) func(c *gin.Context)
- func UserRoutes(endpoint string, r *gin.Engine)
- func WhoFromContext(r *http.Request) models.Who
- func WriteBytes(w http.ResponseWriter, jsonBytes []byte)
- func WriteOK(w http.ResponseWriter)
- func XDebugMiddleWare() gin.HandlerFunc
- type ErrBadRequest
- type ErrClientNotAuthorized
- type ErrCreate
- type ErrDBError
- type ErrDelete
- type ErrGenJSON
- type ErrGeneratingToken
- type ErrInternalServerError
- type ErrInvalidRefreshToken
- type ErrLoginUser
- type ErrNotFound
- type ErrParsingJSON
- type ErrPatch
- type ErrPermissionDeniedForAPIEndpoint
- type ErrQueryParameter
- type ErrReadingBody
- type ErrResponse
- type ErrTokenInvalid
- type ErrURLParameter
- type ErrUpdate
- type JSONBodyWithContent
Constants ¶
const ( // ContextKeyOwnerID is the id that's given in jwt's iss field ContextKeyOwnerID contextKey = iota ContextKeyClient ContextKeyScope ContextKeyIat ContextKeyExp ContextKeyTokenHours )
Variables ¶
This section is empty.
Functions ¶
func BasicToken ¶ added in v0.1.34
BasicToken()
func BearerAuthMiddleware ¶
func BearerAuthMiddleware() gin.HandlerFunc
BearerAuthMiddleware make sure the Bearer token exits and validate it And also get the user ID into the context
func BearerToken ¶ added in v0.1.34
BearerToken returns bearer token
func ChangeEmailPasswordHandler ¶ added in v0.2.2
func ChangeEmailPasswordHandler(typeString string, mapper datamapper.IChangeEmailPasswordMapper) func(c *gin.Context)
ChangeEmailPasswordHandler returns a gin handler which changes password
func ClientAuthMiddleware ¶
func ClientAuthMiddleware() gin.HandlerFunc
ClientAuthMiddleware make users that the software access this API has basic client ID Insert a test one: Insert into client (secret) values ("123");
func ClientFromContext ¶ added in v0.4.2
ClientFromContext gets Client from context
func CreateHandler ¶ added in v0.1.25
func CreateHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
CreateHandler creates a resource
func CreatedTimeRangeFromQueryString ¶ added in v0.4.16
func DeleteManyHandler ¶
func DeleteManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
DeleteManyHandler returns a Gin handler which delete many records
func DeleteOneHandler ¶
func DeleteOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
DeleteOneHandler returns a Gin handler which delete one record
func ExpFromContext ¶ added in v0.1.58
ExpFromContext gets iat from context
func GetOptionByParsingURL ¶ added in v0.4.16
func GetOptionByParsingURL(r *http.Request) (map[datamapper.URLParam]interface{}, error)
func IDFromURLQueryString ¶
IDFromURLQueryString parses resource ID from the URL query string
func IatFromContext ¶ added in v0.1.58
IatFromContext gets iat from context
func JSONPatchesFromJSONBody ¶ added in v0.3.1
JSONPatchesFromJSONBody pares an array of JSON patch from the HTTP body
func LatestnFromQueryString ¶ added in v0.4.16
func LimitAndOffsetFromQueryString ¶ added in v0.4.16
---------------------------------------------
func ModelFromJSONBody ¶
func ModelFromJSONBody(r *http.Request, typeString string, who models.Who) (models.IModel, render.Renderer)
ModelFromJSONBody parses JSON body into a model FIXME: Validation should not be done here because empty field does not pass validation, but sometimes we need empty fields such as patch
func ModelOrModelsFromJSONBody ¶ added in v0.1.24
func ModelOrModelsFromJSONBody(r *http.Request, typeString string, who models.Who) ([]models.IModel, *bool, render.Renderer)
ModelOrModelsFromJSONBody parses JSON body into array of models It take care where the case when it is not even an array and there is a "content" in there
func ModelsFromJSONBody ¶
func ModelsFromJSONBody(r *http.Request, typeString string, who models.Who) ([]models.IModel, render.Renderer)
ModelsFromJSONBody parses JSON body into array of models
func NewErrBadRequest ¶
NewErrBadRequest creates a new ErrBadRequest
func NewErrClientNotAuthorized ¶
NewErrClientNotAuthorized creates a new ErrClientNotAuthorized
func NewErrCreate ¶
NewErrCreate creates a new ErrCreate
func NewErrDBError ¶
NewErrDBError creates a new ErrDBError
func NewErrDelete ¶
NewErrDelete creates a new ErrDelete
func NewErrGenJSON ¶
NewErrGenJSON creates a new ErrGenJSON
func NewErrGeneratingToken ¶
NewErrGeneratingToken creates a new ErrGeneratingToken
func NewErrInternalServerError ¶ added in v0.1.10
NewErrInternalServerError presents error when refreshing a token
func NewErrInvalidRefreshToken ¶
NewErrInvalidRefreshToken presents error when refreshing a token
func NewErrLoginUser ¶
NewErrLoginUser creates a new ErrLoginUser
func NewErrNotFound ¶
NewErrNotFound creates a new ErrNotFound
func NewErrParsingJSON ¶
NewErrParsingJSON creates a new ErrParsingJSON
func NewErrPermissionDeniedForAPIEndpoint ¶ added in v0.1.25
NewErrPermissionDeniedForAPIEndpoint creates a new ErrClientNotAuthorized
func NewErrQueryParameter ¶
NewErrQueryParameter creates a new ErrQueryParameter
func NewErrReadingBody ¶
NewErrReadingBody creates a new ErrReadingBody
func NewErrTokenInvalid ¶
NewErrTokenInvalid creates a new ErrTokenInvalid
func NewErrURLParameter ¶
NewErrURLParameter creates a new ErrURLParameter
func NewErrUpdate ¶
NewErrUpdate creates a new ErrUpdate
func NewErrValidation ¶
NewErrValidation presents validation errors This message is different
func OrderFromQueryString ¶ added in v0.4.16
func OwnerIDFromContext ¶
OwnerIDFromContext gets id from context
func PatchManyHandler ¶ added in v0.3.1
func PatchManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
PatchManyHandler returns a Gin handler which patch (partial update) many records
func PatchOneHandler ¶
func PatchOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
PatchOneHandler returns a Gin handler which patch (partial update) one record
func ReadAllHandler ¶
func ReadAllHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
ReadAllHandler returns a Gin handler which fetch multiple records of a resource
func ReadOneHandler ¶
func ReadOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
ReadOneHandler returns a http.Handler which read one resource
func RenderModel ¶ added in v0.4.16
func RenderModel(w http.ResponseWriter, r *http.Request, typeString string, modelObj models.IModel, role models.UserRole, who models.Who)
RenderModel :-
func RenderModelSlice ¶ added in v0.4.16
func RenderModelSlice(w http.ResponseWriter, r *http.Request, typeString string, modelObjs []models.IModel, roles []models.UserRole, total *int, who models.Who)
RenderModelSlice :-
func ScopeFromContext ¶ added in v0.1.25
ScopeFromContext gets scope from context
func TokenHoursFromContext ¶ added in v0.1.33
TokenHoursFromContext gets hours from context
func UpdateManyHandler ¶
func UpdateManyHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
UpdateManyHandler returns a Gin handler which updates many records
func UpdateOneHandler ¶
func UpdateOneHandler(typeString string, mapper datamapper.IDataMapper) func(c *gin.Context)
UpdateOneHandler returns a http.Handler which updates a resource
func UserLoginHandler ¶
UserLoginHandler logs in the user. Effectively creates a JWT token for the user
func WhoFromContext ¶ added in v0.4.2
WhoFromContext fetches struct Who from request context
func WriteBytes ¶
func WriteBytes(w http.ResponseWriter, jsonBytes []byte)
WriteBytes writes code 0 and a content
func XDebugMiddleWare ¶ added in v0.1.33
func XDebugMiddleWare() gin.HandlerFunc
XDebugMiddleWare parses "X-DEBUG-TOKEN-DURATION-HOURS" if available
Types ¶
type ErrBadRequest ¶
type ErrBadRequest struct {
ErrResponse
}
ErrBadRequest is on all type of errors
type ErrClientNotAuthorized ¶
type ErrClientNotAuthorized struct {
ErrResponse
}
ErrClientNotAuthorized is when client id or secret is not registered or wrong
type ErrDBError ¶
type ErrDBError struct {
ErrResponse
}
ErrDBError some problem operating with DB (maybe transaction)
type ErrDelete ¶
type ErrDelete struct {
ErrResponse
}
ErrDelete some problem deleting resource (not specific yet)
type ErrGenJSON ¶
type ErrGenJSON struct {
ErrResponse
}
ErrGenJSON is error parsing JSON and creating structs
type ErrGeneratingToken ¶
type ErrGeneratingToken struct {
ErrResponse
}
ErrGeneratingToken shows problem with generating key
type ErrInternalServerError ¶ added in v0.1.10
type ErrInternalServerError struct {
ErrResponse
}
ErrInternalServerError some problem refreshing the token (maybe missing)
type ErrInvalidRefreshToken ¶
type ErrInvalidRefreshToken struct {
ErrResponse
}
ErrInvalidRefreshToken some problem refreshing the token (maybe missing)
type ErrLoginUser ¶
type ErrLoginUser struct {
ErrResponse
}
ErrLoginUser problem login user. Maybe the user doesn't exists.
type ErrNotFound ¶
type ErrNotFound struct {
ErrResponse
}
ErrNotFound resource cannot be found (record doesn't exist)
type ErrParsingJSON ¶
type ErrParsingJSON struct {
ErrResponse
}
ErrParsingJSON is error parsing JSON and creating structs
type ErrPatch ¶
type ErrPatch struct {
ErrResponse
}
ErrPatch some problem patching resource (not specific yet) This is not even called right now because not implemented
type ErrPermissionDeniedForAPIEndpoint ¶ added in v0.1.25
type ErrPermissionDeniedForAPIEndpoint struct {
ErrResponse
}
ErrPermissionDeniedForAPIEndpoint is permission denied for this endpoint
type ErrQueryParameter ¶
type ErrQueryParameter struct {
ErrResponse
}
ErrQueryParameter is an error on the URL parameter
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"msg,omitempty"` // user-level status message Code int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging MoreInfo string `json:"moreInfo,omitempty"` // URL link }
Maybe take into consideration my original design
{ "error": "101", "developerMessage": "給開發者看的 message", "userMessage": "給使用者看的簡易 message", "moreInfo": "https://xyz.com/doc/errors/101" }
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
Render is to satisfy the render.Render interface
type ErrTokenInvalid ¶
type ErrTokenInvalid struct {
ErrResponse
}
ErrTokenInvalid token is not valid or expired
type ErrURLParameter ¶
type ErrURLParameter struct {
ErrResponse
}
ErrURLParameter is an error on the URL parameter
type ErrUpdate ¶
type ErrUpdate struct {
ErrResponse
}
ErrUpdate some problem updating resource (not specific yet)
type JSONBodyWithContent ¶ added in v0.1.24
type JSONBodyWithContent struct {
Content []json.RawMessage
}
JSONBodyWithContent for partial unmarshalling