utils

package module
v1.0.1-0...-6fe2199 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, err error)

func BindValidate

func BindValidate(o interface{}) error

BindValidate function

func GetCID

func GetCID(c *gin.Context) (string, error)

func GetServicePath

func GetServicePath(key string) string

func GetUnixTime

func GetUnixTime() string

func NewCID

func NewCID() string

func NewConnection

func NewConnection(ctx context.Context, uri string) *mongo.Client

func NewOID

func NewOID() string

func NewSpreader

func NewSpreader(nConcurrent int) *spreader

func NotOk

func NotOk(c *gin.Context, value interface{})

func Ok

func Ok(c *gin.Context, value interface{})

func PairValues

func PairValues(i, o interface{}) error

PairValues function

func PairValuesArray

func PairValuesArray(in interface{}, out *[]interface{}) error

PairValues function

func ParseKindAndBody

func ParseKindAndBody(c *gin.Context, kind string, result interface{}) error

func ParseKindAndBodyArray

func ParseKindAndBodyArray(c *gin.Context, kind string, result *[]interface{}) error

func RandNumStr

func RandNumStr(n int) string

func RandStr

func RandStr(n int) string

func RandStrLow

func RandStrLow(n int) string

func UnWrap

func UnWrap(payload io.ReadCloser, resultValues interface{}) error

func Unauthorized

func Unauthorized(c *gin.Context, err error)

func UnixToDate

func UnixToDate(unix string) (time.Time, error)

func UnixToDateString

func UnixToDateString(unix string, result *string) error

func UnixToDateStringDefault

func UnixToDateStringDefault(unix, defaultVal string) string

func UnixToFullDateStringDefault

func UnixToFullDateStringDefault(unix, defaultVal string) string

func UnixToTimeFormatDefault

func UnixToTimeFormatDefault(unix, format, defaultVal string) string

Using a custom formatter overriding time.Format()

func UnixToTimeStringDefault

func UnixToTimeStringDefault(unix, defaultVal string) string

func UseMongoTransaction

func UseMongoTransaction(ctx context.Context, mongoClient *mongo.Client, transactionCallback func(sc *mongo.SessionContext) error, tryCount int) error

Passing session inside transactionCallback by value will referring to another session address. Session must be passed by reference instead of passed by value

func WErr

func WErr(error ...string) error

func WrapRequest

func WrapRequest(kind string, values interface{}) interface{}

func WrapToArr

func WrapToArr(results interface{}) interface{}

Types

type BasicCRUDer

type BasicCRUDer interface {
	// GET
	GetByID(ID string, result interface{}) error
	GetByIDs(IDs []string, result interface{}) error
	GetByIDsToMaps(IDs []string, result *[]map[string]interface{}) error

	// CREATE
	Create(Payload interface{}) error

	// UPDATE
	UpdateByID(ID string, query interface{}) error
	UpdateAndGetByID(ID string, query interface{}, result interface{}) error

	// DELETE
	DeleteByID(ID string) error
}

func UseBasicCRUD

func UseBasicCRUD(ctx context.Context, collection *mongo.Collection) BasicCRUDer

Using basic CRUD in mongodb

type Error

type Error struct {
	Code    string      `json:"code" bson:"code" binding:"required"`
	Message interface{} `json:"refs,omitempty" bson:"refs,omitempty"`
}

Error struct

func (Error) Err

func (e Error) Err() string

Err method

type Param

type Param struct {
	List map[string]string
}

func HandleParam

func HandleParam(c *gin.Context, targetParams ...string) (*Param, error)

func (*Param) Get

func (P *Param) Get(param string) string

type Request

type Request struct {
	Kind   string      `json:"kind" bson:"kind" binding:"required"`
	Values interface{} `json:"values" bson:"values" binding:"required"`
}

Request struct

type Response

type Response struct {
	Success bool        `json:"success" bson:"success" binding:"required"`
	Kind    string      `json:"kind,omitempty" bson:"kind,omitempty"`
	Values  interface{} `json:"values,omitempty" bson:"values,omitempty"`
	Error   interface{} `json:"error,omitempty" bson:"error,omitempty"`
}

Response struct

func (*Response) ParseError

func (resp *Response) ParseError() Error

type TCreatedDate

type TCreatedDate struct {
	CreatedAt string `bson:"created_at" json:"created_at"`
	CreatedBy string `bson:"created_by" json:"created_by"`
}

type TDate

type TDate struct {
	TCreatedDate  `bson:",inline"`
	TModifiedDate `bson:",inline"`
}

type TModifiedDate

type TModifiedDate struct {
	ModifiedAt string `bson:"modified_at" json:"modified_at"`
	ModifiedBy string `bson:"modified_by" json:"modified_by"`
}

type TWrappedDate

type TWrappedDate struct {
	DateAttribute TDate `bson:"date_attributes" json:"date_attributes"`
}

func CreateDate

func CreateDate(creator string) TWrappedDate

type TWrappedModifiedDate

type TWrappedModifiedDate struct {
	DateAttribute TModifiedDate `bson:"date_attributes" json:"date_attributes"`
}

func UpdateDate

func UpdateDate(modifier string) TWrappedModifiedDate

Jump to

Keyboard shortcuts

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