Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteMapKeys(m map[string]interface{}, keys ...string)
- func Ternary(rule bool, trueResult interface{}, falseResult interface{}) interface{}
- type Config
- type JSON
- type JSONArray
- type JSONObject
- type Middleware
- type RequestFormatRule
- type Search
- func (s *Search) FilterResult(search JSONObject, model *map[string]interface{})
- func (s *Search) FormatFilters(f interface{}, rule RequestFormatRule) (filters JSONObject)
- func (s *Search) GetQuery(c echo.Context) JSON
- func (s *Search) PopulateFields(search JSONObject, model map[string]interface{}, populate SearchPopulate)
- func (s *Search) RunQuery(collection *bongo.Collection, search JSONObject) []interface{}
- func (s *Search) RunQueryWithPopulate(collection *bongo.Collection, search JSONObject, populate SearchPopulate) []interface{}
- func (s *Search) SearchFormat(query JSON) JSONObject
- func (s *Search) SearchFormatWithRule(query JSON, rule RequestFormatRule) JSONObject
- type SearchPopulate
- type Util
- func (u *Util) AnyOf(values ...interface{}) interface{}
- func (u *Util) ArrayContains(ss interface{}, e interface{}) bool
- func (u *Util) GetBuffer(c echo.Context) (buffer []byte)
- func (u *Util) In(data interface{}, compares ...interface{}) bool
- func (u *Util) InterfaceToBuffer(data interface{}) []byte
- func (u *Util) IsJSON(s interface{}) bool
- func (u *Util) JSONParse(s interface{}) (JSON, error)
- func (u *Util) MapKeyExists(data map[string]interface{}, key string) bool
- func (u *Util) RequestResult(status int, data interface{}, errors interface{}) (int, JSONObject)
- func (u *Util) ResetBuffer(c echo.Context, buffer []byte)
- func (u *Util) StringToFloat(value interface{}) (number float32, err error)
- func (u *Util) StringToInt(value interface{}) (number int, err error)
- func (u *Util) StructToMap(data interface{}) (map[string]interface{}, error)
- func (u *Util) TimeConvert(value interface{}, from string, to string) (result string, err error)
- func (u *Util) ToObjectId(id interface{}) bson.ObjectId
- func (u *Util) ToString(arg interface{}) string
- func (u *Util) TraceError(err error)
Constants ¶
const DATE = "2006-01-02"
noinspection GoUnusedConst
const DATETIME = "2006-01-02 15:04:05"
noinspection GoUnusedConst
Variables ¶
var Configs = Config{}
noinspection GoUnusedGlobalVariable
var Middlewares = Middleware{}
noinspection GoUnusedGlobalVariable
var Searchs = Search{}
noinspection GoUnusedGlobalVariable
var Utils = Util{}
noinspection GoUnusedGlobalVariable
Functions ¶
func DeleteMapKeys ¶
noinspection GoUnusedExportedFunction
Types ¶
type Config ¶
type Config struct{}
func (*Config) Connection ¶
func (c *Config) Connection() *bongo.Connection
func (*Config) Environment ¶
* For project environment, need to set GOENV with environment type
type JSONObject ¶
type Middleware ¶
type Middleware struct{}
func (*Middleware) FormatErrorResponse ¶
func (m *Middleware) FormatErrorResponse(next echo.HandlerFunc) echo.HandlerFunc
Middleware to format when returns an error object
func (*Middleware) JsonBodyAsArray ¶
func (m *Middleware) JsonBodyAsArray(next echo.HandlerFunc) echo.HandlerFunc
func (*Middleware) JsonFormatFields ¶
func (m *Middleware) JsonFormatFields(formatter RequestFormatRule) echo.MiddlewareFunc
* Middleware Run all JSON body fields, and format the need
type RequestFormatRule ¶
* Rule structure
type Search ¶
type Search struct{}
func (*Search) FilterResult ¶
func (s *Search) FilterResult(search JSONObject, model *map[string]interface{})
Filter result fields
func (*Search) FormatFilters ¶
func (s *Search) FormatFilters(f interface{}, rule RequestFormatRule) (filters JSONObject)
Format query=filter content to MongoDB pattern
func (*Search) GetQuery ¶
Format $_GET string query to JSON structure Uses bellow pattern: - search: MongoDB custom formatted query - filter: List of fields to remove from response - result: List of fields to return from response - populate: List of fields can be populated
func (*Search) PopulateFields ¶
func (s *Search) PopulateFields(search JSONObject, model map[string]interface{}, populate SearchPopulate)
Populate result fields
func (*Search) RunQuery ¶
func (s *Search) RunQuery(collection *bongo.Collection, search JSONObject) []interface{}
Run MongoDB search and result filtering
func (*Search) RunQueryWithPopulate ¶
func (s *Search) RunQueryWithPopulate(collection *bongo.Collection, search JSONObject, populate SearchPopulate) []interface{}
Run MongoDB search, result filtering and populate
func (*Search) SearchFormat ¶
func (s *Search) SearchFormat(query JSON) JSONObject
Format query filter parameters with MongoDB pattern
func (*Search) SearchFormatWithRule ¶
func (s *Search) SearchFormatWithRule(query JSON, rule RequestFormatRule) JSONObject
Format query filter parameters with MongoDB pattern and rule
type SearchPopulate ¶
* Populate structure
type Util ¶
type Util struct{}
func (*Util) AnyOf ¶
func (u *Util) AnyOf(values ...interface{}) interface{}
* AnyOf Check for first not nil value, use as var1 || var2 shortcut
func (*Util) ArrayContains ¶
Search if a value contains inside array
func (*Util) InterfaceToBuffer ¶
func (*Util) MapKeyExists ¶
Check if map key exists
func (*Util) RequestResult ¶
func (u *Util) RequestResult(status int, data interface{}, errors interface{}) (int, JSONObject)
func (*Util) StringToFloat ¶
Validate if value is string, if is, try to convert to float/32. If error, returns -999
func (*Util) StringToInt ¶
Validate if value is string, if is, try to convert to int. If error, returns -999
func (*Util) StructToMap ¶
Convert struct to string key map
func (*Util) TimeConvert ¶
Validate if value is string and try to convert one time format to another format
func (*Util) ToObjectId ¶
Validate an interface{} var and return an MongoDB ObjectId