utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Charset    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	RandLength = 5
)

constants generator

View Source
const (
	Success       = "200"
	Error         = "500"
	InvalidParams = "400"

	ErrorGetDatabase = "1001"

	ErrorExistProduct      = "10001"
	ErrorExistProductFail  = "10002"
	ErrorNotExistProduct   = "10003"
	ErrorGetProductsFail   = "10004"
	ErrorCountProductFail  = "10005"
	ErrorAddProductFail    = "10006"
	ErrorEditProductFail   = "10007"
	ErrorDeleteProductFail = "10008"
	ErrorExportProductFail = "10009"
	ErrorImportProductFail = "10010"

	ErrorNotExistUser       = "20001"
	ErrorCheckExistUserFail = "20002"
	ErrorAddUserFail        = "20003"
	ErrorDeleteUserFail     = "20004"
	ErrorEditUserFail       = "20005"
	ErrorCountUserFail      = "20006"
	ErrorGetUsersFail       = "20007"
	ErrorGetUserFail        = "20008"
	ErrorGenUserPosterFail  = "20009"

	ErrorAuthCheckTokenFail    = "30001"
	ErrorAuthCheckTokenTimeout = "30002"
	ErrorAuthToken             = "30003"
	ErrorAuth                  = "30004"
)

constants responses

Variables

View Source
var (
	JSONMarshal       = json.Marshal
	JSONUnmarshal     = json.Unmarshal
	JSONMarshalIndent = json.MarshalIndent
	JSONNewDecoder    = json.NewDecoder
	JSONNewEncoder    = json.NewEncoder
)

JSON

Functions

func Copy

func Copy(dest interface{}, src interface{}) error

Copy by marshal json data

func GenerateCode

func GenerateCode(prefix string) string

GenerateCode generate code by prefix, datetime

func HashPassword

func HashPassword(pass []byte) (string, error)

HashPassword hash password

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON

func PrepareResponse

func PrepareResponse(data interface{}, message string, code string) map[string]interface{}

PrepareResponse return new response body type map

func RandomString

func RandomString(length int) string

RandomString random string by charset and length

func Validate

func Validate(values []Validation) bool

Validate by key and value

Types

type Validation

type Validation struct {
	Value string
	Valid string
}

Validation struct

Jump to

Keyboard shortcuts

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