util

package
v0.0.0-...-6d6c219 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayDiff

func ArrayDiff(src, compare []string) (diff []string)

for each element in 'compare', if NOT in 'src', it will be added to the resulting 'diff' if you want to add from an existing, compared to another list, src => existing; compare => new list if you wnat to delete from to an existing, compared to another list, src => new list; compare => existing

func BuildSearchString

func BuildSearchString(param Param, excludeWhere bool) (string, []interface{})

func GenerateRandomString

func GenerateRandomString(l int) string

func GenerateUUID

func GenerateUUID() string

func GetTypeCount

func GetTypeCount(i interface{}) int

func HTTPRequest

func HTTPRequest(method, url string, bodyIn, bodyOut interface{}, header map[string]string) (err error)

a simplified http client to call external http servers, it is designed to fail if the status code is not in the 200's inputs:

method: standard http method, i.e.: POST, GET, PATCH, etc
url: the full http url
bodyIn: map or struct, this function will json.Marshal it for the body payload, pass in 'nil' if not needed
bodyOut: map or *struct, this function will json.Unmarshal the response.Body to this variable
headers: map[string]string of headers to add to the request

func LogError

func LogError(c echo.Context, apiError *ae.ApiError)

func TxnFinish

func TxnFinish(tx *sqlx.Tx, err *error)

func ValidJson

func ValidJson(jsonValue json.RawMessage) bool

Types

type Error

type Error struct {
	Id     string `json:"Id,omitempty"`
	Title  string `json:"Title,omitempty"`
	Detail string `json:"Detail,omitempty"`
	Status string `json:"Status,omitempty"`
}

type Filter

type Filter struct {
	Column  string      `json:"column"`
	Compare string      `json:"compare"`
	Value   interface{} `json:"value"`
}

type Meta

type Meta struct {
	TotalCount int `json:"total_count"`
}

type Output

type Output struct {
	Payload interface{} `json:"data,omitempty"`
	*Error  `json:"error,omitempty"`
	*Meta   `json:"meta,omitempty"`
}

func NewOutput

func NewOutput(c echo.Context, payload interface{}, apiError *ae.ApiError, totalCount *int) Output

type Pagination

type Pagination struct {
	PageLimit  int `json:"page_limit"`
	PageNumber int `json:"page_number"`
}

type Param

type Param struct {
	Search           Search `json:"search"`
	Limit            int    // holds the calculated limit
	Offset           int    // holds the offset number
	PaginationString string // holds the limit/offset tring
	Sort             string // holds the calculated sort string
	ColumnMapping    map[string]string
}

func (*Param) CalculateParam

func (p *Param) CalculateParam(primarySort string, availableSort map[string]string) (err error)
type Search struct {
	Filters    []Filter   `json:"filters"`
	Pagination Pagination `json:"pagination"`
	Sort       string     `json:"sort"` // comma separated string, use a '-' before column name to sort DESC i.e.: id,-name => "SORT BY id ASC, name DESC"
}

type SearchBuilder

type SearchBuilder struct {
	Params       []string
	Values       []interface{}
	ExcludeWhere bool
}

func (*SearchBuilder) AppendCompare

func (s *SearchBuilder) AppendCompare(param, compare string, value interface{})

func (*SearchBuilder) AppendIn

func (s *SearchBuilder) AppendIn(param string, value interface{})

this will produce a string that represents an "IN" clause as long as the incoming arg 'value' is of type slice or array the output will always be sql string array, most DB engines will deal with the single quotes even if the underlying columns is not a text type []string{1, 2, 3} => IN ('1', '2', '3'), this is what is expected

func (*SearchBuilder) AppendLike

func (s *SearchBuilder) AppendLike(param, value string)

func (*SearchBuilder) AppendNull

func (s *SearchBuilder) AppendNull(param string, wantNull bool)

func (*SearchBuilder) String

func (s *SearchBuilder) String() string

Jump to

Keyboard shortcuts

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