Documentation ¶
Index ¶
- Constants
- Variables
- func AUTH(next http.Handler, secret string) http.Handler
- func CORS(next http.Handler) http.Handler
- func CreateJWTToken(secret string, expirationDelta time.Duration) (string, error)
- func LOGS(next http.Handler) http.Handler
- func MustHaveGroupRole(next http.Handler, groupID, roleID int) http.Handler
- func ParseURLParamInt64(req *http.Request, param string) (int64, error)
- func SetPermissions(r *http.Request, permissions []GroupRoles)
- type AppHandler
- type FieldError
- type FieldErrors
- type GroupRoles
- type ID
- type NullBool
- type NullFloat64
- type NullInt64
- type NullString
- type NullTime
- type Response
- func BadRequestErrorsResponse(errors FieldErrors) Response
- func BadRequestResponse(err error) Response
- func DeletedResponse(count int64) Response
- func FileDownloadResponse(file *os.File, filename string) Response
- func InternalErrorResponse(err error) Response
- func PagedResponse(result interface{}, page, per_page, total int64) Response
- func SuccessResult(result interface{}) Response
- func UnauthorisedResponse(err error) Response
- func UpdatedResponse(count int64) Response
- func UserErrorResponse(err error) Response
- type ResponseType
- type SubResponseDeleted
- type SubResponsePaged
- type SubResponseUpdated
Constants ¶
View Source
const PermissionsContextKey contextKey = "permissions"
View Source
const PermissionsKey key = 123234
Variables ¶
View Source
var ( ErrRequiredField error = errors.New("*Required field") ErrUnsupportedValue error = errors.New("unsupported Value") ErrRecordDoesntExist error = errors.New("record does not exist") ErrNotImplemented error = errors.New("Endpoint not implemented") ErrBadJSONBody error = errors.New("unable to parse body, exptected json") )
View Source
var ErrIncorrectPermissions error = errors.New("incorrect permissions, missing group or role to perform this action")
Functions ¶
func CreateJWTToken ¶
func MustHaveGroupRole ¶
func ParseURLParamInt64 ¶
This function parses the request URL and returns the parameter given by name in param. E.g. /project/{PprojectID} --> "ProjecID" is the URL param
func SetPermissions ¶
func SetPermissions(r *http.Request, permissions []GroupRoles)
Types ¶
type AppHandler ¶
func (AppHandler) ServeHTTP ¶
func (fn AppHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
type FieldError ¶
type FieldErrors ¶
type FieldErrors []FieldError
func (*FieldErrors) Append ¶
func (e *FieldErrors) Append(field, message string)
type GroupRoles ¶
func GetPermissions ¶
func GetPermissions(req *http.Request) []GroupRoles
type NullFloat64 ¶
type NullFloat64 struct {
sql.NullFloat64
}
func (NullFloat64) MarshalJSON ¶
func (n NullFloat64) MarshalJSON() ([]byte, error)
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(data []byte) error
type NullString ¶
type NullString struct {
sql.NullString
}
func NewNullString ¶
func NewNullString(value string, valid bool) NullString
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
func (*NullString) Set ¶
func (n *NullString) Set(value string)
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(data []byte) error
type Response ¶
type Response struct { Status bool `json:"success"` Type ResponseType `json:"-"` Result interface{} `json:"response,omitempty"` Error string `json:"error,omitempty"` Errors FieldErrors `json:"errors,omitempty"` Updated *SubResponseUpdated `json:"updated,omitempty"` Deleted *SubResponseDeleted `json:"deleted,omitempty"` Paged *SubResponsePaged `json:"paged,omitempty"` File *os.File `json:"-"` FileName string `json:"-"` }
func BadRequestErrorsResponse ¶
func BadRequestErrorsResponse(errors FieldErrors) Response
func BadRequestResponse ¶
func DeletedResponse ¶
func InternalErrorResponse ¶
func PagedResponse ¶
func SuccessResult ¶
func SuccessResult(result interface{}) Response
func UnauthorisedResponse ¶
func UpdatedResponse ¶
func UserErrorResponse ¶
type ResponseType ¶
type ResponseType int
const ( RESPOND_OK ResponseType = iota RESPOND_BAD_REQUEST RESPOND_INTERNAL_ERROR RESPOND_USER_ERROR RESPOND_DELETED RESPOND_UPDATED RESPOND_PAGED RESPOND_FILE_DOWNLOAD RESPOND_UNAUTHORISED )
type SubResponseDeleted ¶
type SubResponseDeleted struct {
Count int64 `json:"count"`
}
type SubResponsePaged ¶
type SubResponseUpdated ¶
type SubResponseUpdated struct {
Count int64 `json:"count"`
}
Click to show internal directories.
Click to hide internal directories.