unio

package module
v0.0.0-...-7c5c8e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 16 Imported by: 0

README

Unio for Go

License

Utility framework for Go development

Install

go get -u github.com/unio-framework/go

Test

Echo

This framework uses some functions to work with Echo Web Framework

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

View Source
const DATE = "2006-01-02"

noinspection GoUnusedConst

View Source
const DATETIME = "2006-01-02 15:04:05"

noinspection GoUnusedConst

Variables

View Source
var Configs = Config{}

noinspection GoUnusedGlobalVariable

View Source
var Middlewares = Middleware{}

noinspection GoUnusedGlobalVariable

View Source
var Searchs = Search{}

noinspection GoUnusedGlobalVariable

View Source
var Utils = Util{}

noinspection GoUnusedGlobalVariable

Functions

func DeleteMapKeys

func DeleteMapKeys(m map[string]interface{}, keys ...string)

noinspection GoUnusedExportedFunction

func Ternary

func Ternary(rule bool, trueResult interface{}, falseResult interface{}) interface{}

noinspection GoUnusedExportedFunction

Types

type Config

type Config struct{}

func (*Config) Connection

func (c *Config) Connection() *bongo.Connection

func (*Config) Env

func (c *Config) Env(key string) string

* Shortcut to get an environment

func (*Config) Environment

func (c *Config) Environment() string

* For project environment, need to set GOENV with environment type

func (*Config) Init

func (c *Config) Init()

* Start all configuratio

func (*Config) LoadEnv

func (c *Config) LoadEnv()

* Load enviroment variables

type JSON

type JSON interface{}

JSON types

type JSONArray

type JSONArray []JSON

type JSONObject

type JSONObject map[string]JSON

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

type RequestFormatRule func(method string, key string, value interface{}) interface{}

* Rule structure

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

func (s *Search) GetQuery(c echo.Context) JSON

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

type SearchPopulate func(field string, value interface{}) (interface{}, error)

* 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

func (u *Util) ArrayContains(ss interface{}, e interface{}) bool

Search if a value contains inside array

func (*Util) GetBuffer

func (u *Util) GetBuffer(c echo.Context) (buffer []byte)

func (*Util) In

func (u *Util) In(data interface{}, compares ...interface{}) bool

* In Compare if data is one of comparators

func (*Util) InterfaceToBuffer

func (u *Util) InterfaceToBuffer(data interface{}) []byte

func (*Util) IsJSON

func (u *Util) IsJSON(s interface{}) bool

Check if a interface has JSON pattern

func (*Util) JSONParse

func (u *Util) JSONParse(s interface{}) (JSON, error)

Parse any to JSON structure

func (*Util) MapKeyExists

func (u *Util) MapKeyExists(data map[string]interface{}, key string) bool

Check if map key exists

func (*Util) RequestResult

func (u *Util) RequestResult(status int, data interface{}, errors interface{}) (int, JSONObject)

func (*Util) ResetBuffer

func (u *Util) ResetBuffer(c echo.Context, buffer []byte)

func (*Util) StringToFloat

func (u *Util) StringToFloat(value interface{}) (number float32, err error)

Validate if value is string, if is, try to convert to float/32. If error, returns -999

func (*Util) StringToInt

func (u *Util) StringToInt(value interface{}) (number int, err error)

Validate if value is string, if is, try to convert to int. If error, returns -999

func (*Util) StructToMap

func (u *Util) StructToMap(data interface{}) (map[string]interface{}, error)

Convert struct to string key map

func (*Util) TimeConvert

func (u *Util) TimeConvert(value interface{}, from string, to string) (result string, err error)

Validate if value is string and try to convert one time format to another format

func (*Util) ToObjectId

func (u *Util) ToObjectId(id interface{}) bson.ObjectId

Validate an interface{} var and return an MongoDB ObjectId

func (*Util) ToString

func (u *Util) ToString(arg interface{}) string

ToString Change arg to string

func (*Util) TraceError

func (u *Util) TraceError(err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL