Documentation ¶
Index ¶
- Constants
- func GetExtAndFileTypeByMimeType(data []byte) (string, string)
- func GetMimeTypesByExt(extensions ...string) []string
- func GetPaginationSettings(c *routing.Context, total int) (int, int)
- func GetSearchConditions(c *routing.Context, validFields []string) bson.M
- func GetSortFields(c *routing.Context, validFields []string) []string
- func InterfaceToObjectIds(val interface{}) []bson.ObjectId
- func InterfaceToStrings(val interface{}) []string
- func MD5(str string) string
- func Random(length int) string
- func RenderTemplateFiles(data interface{}, files ...string) (string, error)
- func RenderTemplateStrings(data interface{}, content ...string) (string, error)
- func SendEmail(from, to, subject, body string) error
- func SendHook(url string, hookType string, hookAction string, hookData interface{}) error
- func SendJsonPostData(url string, data []byte) error
- func Sentenize(str string) string
- func SetPaginationHeaders(c *routing.Context, limit int, total int, currentPage int)
- func StringInSlice(str string, list []string) bool
- func UcFirst(str string) string
- func ValidateMimeType(data []byte, validTypes []string) bool
- func ValidateSize(data []byte, maxValidSize float64) bool
- type ApiError
- type DataError
- type Hook
Constants ¶
const ( // HookTypeCollection specify the `collection` type hook. HookTypeCollection = "collection" // HookTypeEntity specify the `entity` type hook. HookTypeEntity = "entity" // HookActionCreate specify the `create` action hook. HookActionCreate = "create" // HookActionUpdate specify the `update` action hook. HookActionUpdate = "update" // HookActionDelete specify the `delete` action hook. HookActionDelete = "delete" )
const FILE_TYPE_AUDIO = "audio"
const FILE_TYPE_DOC = "doc"
const FILE_TYPE_IMAGE = "image"
const FILE_TYPE_OTHER = "other"
const FILE_TYPE_VIDEO = "video"
const SearchSpecialChar = "~"
SearchSpecialChar stores the special character used to simulate LIKE query search NB! need to be valid url and non escapable regex string character(s)
Variables ¶
This section is empty.
Functions ¶
func GetExtAndFileTypeByMimeType ¶
GetExtAndFileTypeByMimeType returns data extension and file type by its mime type.
func GetMimeTypesByExt ¶
GetMimeTypesByExt returns all mime types related to extension(s).
func GetPaginationSettings ¶
GetPaginationSettings extracts and returns common pagination settings from a request.
func GetSearchConditions ¶
GetSearchConditions builds and returns bson collection find condition from a request.
func GetSortFields ¶
GetSortFields formats and returns sort fields from a request.
func InterfaceToObjectIds ¶
InterfaceToObjectIds extracts and converts slice of hex strings or ObjectIds to slice of ObjectIds.
func InterfaceToStrings ¶
func InterfaceToStrings(val interface{}) []string
InterfaceToStrings extracts and converts slice of interfaces to slice of strings.
func RenderTemplateFiles ¶
RenderTemplateFiles renders html templates and returns the result as a string.
func RenderTemplateStrings ¶
RenderTemplateStrings resolves inline html template strings.
func SendJsonPostData ¶
SendJsonPostData sends json post request data.
func SetPaginationHeaders ¶
SetPaginationHeaders sets common pagination related headers.
func StringInSlice ¶
StringInSlice checks whether a string exist in array/slice.
func ValidateMimeType ¶
ValidateMimeType validates data mime type.
func ValidateSize ¶
ValidateSize validates data size.
Types ¶
type ApiError ¶
type ApiError struct { Status int `json:"status"` Message string `json:"message"` Data interface{} `json:"data"` }
ApiError defines the properties for a basic api error response.
func NewApiError ¶
NewApiError creates and returns new normalized ApiError instance.
func NewBadRequestError ¶
NewBadRequestError creates and returns 400 ApiError.
func NewNotFoundError ¶
NewNotFoundError creates and returns 404 ApiError.
func (*ApiError) StatusCode ¶
StatusCode returns the HTTP status code.
type DataError ¶
type DataError struct {
Data interface{} `json:"data"`
}
DataError defines the properties for a basic data error structure.
func NewDataError ¶
func NewDataError(data interface{}) *DataError
NewDataError initilizes and returns a new DataError.
func (*DataError) MarshalJSON ¶
MarshalJSON handles json serialization