util

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: MIT Imports: 5 Imported by: 0

README

go-util

go utils

package util

Documentation

Index

Constants

View Source
const (
	ZeroInt     = 0
	ZeroFloat64 = 0
	ZeroString  = ""
	ZeroBool    = false
)
View Source
const (
	// ExternalOK means the code from external server status code.
	ExternalOK = 1

	// ReturnSuccess = 0
	ReturnSuccess = -1 + iota
	// ReturnExternalServerError map to external server error code 1
	ReturnExternalServerError
	// ReturnParamsError map to external server error code 2
	ReturnParamsError
	// ReturnJSONError map to external server error code 3
	ReturnJSONError
	// ReturnAlreadyLogin map to external server error code 4
	ReturnAlreadyLogin
	// ReturnAccountOrPasswordError map to external server error code 5
	ReturnAccountOrPasswordError
	// ReturnSessionError map to external server error code 6
	ReturnSessionError
	// ReturnPasswordNotMatched map to external server error code 7
	ReturnPasswordNotMatched
	// ReturnAccountNotExist map to external server error code 8
	ReturnAccountNotExist

	// ReturnServerError is 503 server internal error. code 9
	ReturnServerError
	// ReturnUnauthorized is 401 Unauthorized error. code 10
	ReturnUnauthorized
)

Variables

View Source
var (
	// ErrMapFetcherKeyNotExist means the input key is not exist.
	ErrMapFetcherKeyNotExist = errors.New("map fetcher: key not exist")
	// ErrMapFetcherFaildAssertionTimeType means the time.Time type assertion faild.
	ErrMapFetcherFaildAssertionTimeType = errors.New("time.Time type assertion failed")
	// ErrMapFetcherFaildAssertionFloatType means the float64 type assertion faild.
	ErrMapFetcherFaildAssertionFloatType = errors.New("float64 type assertion failed")
	// ErrMapFetcherFaildAssertionStringType means the string type assertion faild.
	ErrMapFetcherFaildAssertionStringType = errors.New("string type assertion failed")
	// ErrMapFetcherFaildAssertionIntType means the int type assertion faild.
	ErrMapFetcherFaildAssertionIntType = errors.New("int type assertion failed")
	// ErrMapFetcherFaildAssertionBoolType means the bool type assertion faild.
	ErrMapFetcherFaildAssertionBoolType = errors.New("bool type assertion failed")
)

Functions

func NewReturn

func NewReturn(kumayErr error, data string) ([]byte, error)

NewReturn returns the unified output in JSON format.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a counting usage struct and provides functions to help couting.

func NewCounter

func NewCounter(num int) *Counter

NewCounter returns a Counter instance and the input num is the init number of the counter.

func (*Counter) Get

func (c *Counter) Get() int

Get returns the current count number.

func (*Counter) PlusNum

func (c *Counter) PlusNum(num int)

PlusNum plus the input number to the counter.

func (*Counter) PlusPlus

func (c *Counter) PlusPlus()

PlusPlus plus one to the counter.

func (*Counter) SubNum

func (c *Counter) SubNum(num int)

SubNum sub the input number to the counter.

func (*Counter) SubSub

func (c *Counter) SubSub()

SubSub sub one to the counter.

type Err

type Err struct {
	Code int
	Msg  error
}

Err is the inner error tranport format.

func NewErr

func NewErr(code int, msg error) *Err

NewErr returns a Err instance.

func (*Err) Error

func (e *Err) Error() string

type MapFetcher

type MapFetcher struct {
	// contains filtered or unexported fields
}

MapFetcher is the wrapper for map[string]interface{}, and provides actions for easy usage of map actions.

func NewMapfetcher

func NewMapfetcher(data map[string]interface{}) *MapFetcher

NewMapfetcher returns MapFetcher instance.

func (*MapFetcher) Add

func (mf *MapFetcher) Add(key string, value interface{})

Add adds key value into map.

func (*MapFetcher) ClearErr

func (mf *MapFetcher) ClearErr()

ClearErr clears the error.

func (*MapFetcher) CopyMap

func (mf *MapFetcher) CopyMap(from *MapFetcher)

CopyMap copies a MapFetcher's data map into self data map.

func (*MapFetcher) Err

func (mf *MapFetcher) Err() error

Err returns MapFetcher holds err, it is using this article's thoughts: https://blog.golang.org/errors-are-values

func (*MapFetcher) Fetch

func (mf *MapFetcher) Fetch(key string) interface{}

Fetch returns interface{} in the holding map by input key.

func (*MapFetcher) FetchBool

func (mf *MapFetcher) FetchBool(key string) bool

FetchBool converts specific key value into boolean then returns.

func (*MapFetcher) FetchFloat

func (mf *MapFetcher) FetchFloat(key string) float64

FetchFloat converts specific key value into float64 then returns.

func (*MapFetcher) FetchInt

func (mf *MapFetcher) FetchInt(key string) int

FetchInt converts specific key value into int then returns.

func (*MapFetcher) FetchString

func (mf *MapFetcher) FetchString(key string) string

FetchString converts specific key value into string then returns.

func (*MapFetcher) FetchTime

func (mf *MapFetcher) FetchTime(key string) time.Time

FetchTime converts specific key value into time.Time then returns.

func (*MapFetcher) FetchTimeFromString

func (mf *MapFetcher) FetchTimeFromString(key, location string) time.Time

FetchTimeFromString converts specific key value from string time into time.Time then returns.

func (*MapFetcher) GetMap

func (mf *MapFetcher) GetMap() map[string]interface{}

GetMap returns whole map.

func (*MapFetcher) Len

func (mf *MapFetcher) Len() int

Len returns the self data map length.

func (*MapFetcher) Remove

func (mf *MapFetcher) Remove(key string)

Remove removes a key from map.

type ReturnForm

type ReturnForm struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data string `json:"data"`
}

ReturnForm is the kumay all server output form.

Directories

Path Synopsis
testify
* https://github.com/satori/go.uuid
* https://github.com/satori/go.uuid

Jump to

Keyboard shortcuts

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