Documentation ¶
Overview ¶
数据转换
Index ¶
- Constants
- Variables
- func AddStatus(status *Status)
- func AddStatusText(lang string, code int32, text string)
- func AppendPrivateBlocks(bs ...string)
- func BoolElem() reflect.Value
- func BoolSliceElem() reflect.Value
- func Cause(err error) error
- func Certificate(host ...string) (tls.Certificate, error)
- func DeepCopy(dst, src interface{}) error
- func Elem(v reflect.Type) reflect.Value
- func Extract(addr string) (string, error)
- func Float32Elem() reflect.Value
- func Float32SliceElem() reflect.Value
- func Float64Elem() reflect.Value
- func Float64SliceElem() reflect.Value
- func GenTK(account string) string
- func GetText(lang string, code int32) string
- func HostPort(addr string, port interface{}) string
- func IPs() []string
- func InFloat32Slice(v float32, sl []float32) bool
- func InFloat64Slice(v float64, sl []float64) bool
- func InInt32Slice(v int32, sl []int32) bool
- func InInt64Slice(v int64, sl []int64) bool
- func InIntSlice(v int, sl []int) bool
- func InSlice(v interface{}, slice interface{}) bool
- func InStrSlice(v string, sl []string) bool
- func Int32Elem() reflect.Value
- func Int32MapElem(v reflect.Type) reflect.Value
- func Int32SliceElem() reflect.Value
- func Int32SliceUnique(slice []int32) (uniqueslice []int32)
- func Int64Elem() reflect.Value
- func Int64MapElem(v reflect.Type) reflect.Value
- func Int64SliceElem() reflect.Value
- func Int64SliceIface(slice []int64) (result []interface{})
- func Int64SliceUnique(slice []int64) (uniqueslice []int64)
- func IntElem() reflect.Value
- func IntMapElem(v reflect.Type) reflect.Value
- func IntSliceElem() reflect.Value
- func IntSliceIface(slice []int) (result []interface{})
- func Is(a, b error) bool
- func IsCode(err error, code int32) bool
- func IsLocal(addr string) bool
- func IsStack() bool
- func Listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, error)
- func MapElem(k, v reflect.Type) reflect.Value
- func ParseBool(v interface{}) bool
- func ParseFloat32(v interface{}) float32
- func ParseFloat64(v interface{}) float64
- func ParseInt(v interface{}) int
- func ParseInt32(v interface{}) int32
- func ParseInt64(v interface{}) int64
- func ParseSlice(v interface{}) []interface{}
- func ParseStr(v interface{}) string
- func ParseStrSlice(v []interface{}) []string
- func ParseTK(token string) (string, error)
- func ParseUint(v interface{}) uint
- func ParseUint32(v interface{}) uint32
- func ParseUint64(v interface{}) uint64
- func Proxy(service string, address []string) (string, []string, bool)
- func Ptr(v reflect.Type) reflect.Value
- func RandSlice(slice interface{})
- func SetDefaultLang(lang string)
- func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})
- func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})
- func SliceElem(v reflect.Type) reflect.Value
- func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})
- func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})
- func SliceMerge(slice1, slice2 []interface{}) (c []interface{})
- func SlicePad(slice []interface{}, size int, val interface{}) []interface{}
- func SliceRand(a []interface{}) (b interface{})
- func SliceRandList(min, max int) []int
- func SliceRandStr(a []string) (b string)
- func SliceRange(start, end, step int64) (intslice []int64)
- func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})
- func SliceShuffle(slice []interface{}) []interface{}
- func SliceShuffleInt(slice []int) []int
- func SliceSum(intslice []int64) (sum int64)
- func SliceTwoElem(v reflect.Type) reflect.Value
- func SliceUnique(slice []interface{}) (uniqueslice []interface{})
- func SplitStrSlice(str string, sep string) []interface{}
- func StatusText(code int32) string
- func StrElem() reflect.Value
- func StrMapElem(v reflect.Type) reflect.Value
- func StrSliceElem() reflect.Value
- func StrSliceIface(slice []string) (result []interface{})
- func StrSliceUnique(slice []string) (uniqueslice []string)
- func StructToDict(data interface{}) map[string]interface{}
- func ToDict(data interface{}) map[string]interface{}
- func ToJson(data interface{}) []byte
- func ToStruct(data interface{}, obj interface{}) error
- func Wrap(err error, args ...interface{}) error
- type Buffer
- type Entry
- type Error
- func Exists(args ...interface{}) *Error
- func Finished(args ...interface{}) *Error
- func Forbidden(args ...interface{}) *Error
- func Invalid(args ...interface{}) *Error
- func New(code int32, a ...interface{}) *Error
- func NotFound(args ...interface{}) *Error
- func Other(args ...interface{}) *Error
- func Parse(err error) *Error
- func Server(args ...interface{}) *Error
- func Started(args ...interface{}) *Error
- func Timeout(args ...interface{}) *Error
- func Unauthorized(args ...interface{}) *Error
- func Unavailable(args ...interface{}) *Error
- func Universal(args ...interface{}) *Error
- func Unknown(args ...interface{}) *Error
- type Frame
- type StackTrace
- type Status
- type Stream
Constants ¶
const ( CodeOk int32 = 0 CodeUniversal = 1 CodeUnknown = 2 CodeInvalid = 3 CodeExists = 4 CodeStarted = 90 CodeFinished = 91 CodeOther = 99 // HTTP Status Code (100 ~ 600) CodeForbidden = 403 CodeNotFound = 404 CodeTimeout = 408 CodeServerError = 500 ErrNewPlayer // 创建玩家失败 ErrTokenEmpty // token is empty ErrTokenDecrypt // token decrypt failed ErrTokenFormat // token format is invalid ErrTokenExpired // token expired UnknownError // 未知错误 ErrParam // 参数错误 ErrParamNil // 请求参数为空 ErrParse // 解析失败 ErrDB // 数据库操作失败 ErrRedis // 缓存操作失败 ErrConnect // 连接失败 )
Game System Error Code (1 ~ 99)
const ( MyTimeInterval = 60 * 10 MyTimeExpired = 60 * 60 * 24 )
Variables ¶
var ( RefTypeStr = reflect.TypeOf("") RefTypeInt = reflect.TypeOf(0) RefTypeInt32 = reflect.TypeOf(int32(0)) RefTypeInt64 = reflect.TypeOf(int64(0)) RefTypeFloat32 = reflect.TypeOf(float32(0)) RefTypeFloat64 = reflect.TypeOf(float64(0)) RefTypeBool = reflect.TypeOf(false) )
var ( Lang = map[string]*Status{ "en-us": NewStatus("en-us"), "zh-cn": NewStatus("zh-cn"), } )
Functions ¶
func AddStatusText ¶
AddStatusText 注册语言环境信息
func AppendPrivateBlocks ¶
func AppendPrivateBlocks(bs ...string)
AppendPrivateBlocks append private network blocks
func BoolSliceElem ¶
func Cause ¶
Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:
type causer interface { Cause() error }
If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.
func Certificate ¶
func Certificate(host ...string) (tls.Certificate, error)
func Float32Elem ¶
func Float32SliceElem ¶
func Float64Elem ¶
func Float64SliceElem ¶
func InFloat32Slice ¶ added in v0.0.4
InInt64Slice checks given int64 in int64 slice or not.
func InFloat64Slice ¶ added in v0.0.4
InInt64Slice checks given int64 in int64 slice or not.
func InInt32Slice ¶ added in v0.0.4
InInt32Slice checks given int in int slice or not.
func InInt64Slice ¶ added in v0.0.4
InInt64Slice checks given int64 in int64 slice or not.
func InIntSlice ¶ added in v0.0.4
InIntSlice checks given int in int slice or not.
func InSlice ¶ added in v0.0.4
func InSlice(v interface{}, slice interface{}) bool
InSlice checks given interface in interface slice.
func InStrSlice ¶ added in v0.0.4
InStrSlice checks given string in string slice or not.
func Int32SliceElem ¶
func Int32SliceUnique ¶ added in v0.0.4
Int32SliceUnique cleans repeated values in slice.
func Int64SliceElem ¶
func Int64SliceIface ¶ added in v0.0.4
func Int64SliceIface(slice []int64) (result []interface{})
Int64SliceIface 数字切片转 []interface{}
func Int64SliceUnique ¶ added in v0.0.4
Int64SliceUnique cleans repeated values in slice.
func IntSliceElem ¶
func IntSliceIface ¶ added in v0.0.4
func IntSliceIface(slice []int) (result []interface{})
IntSliceIface 数字切片转 []interface{}
func Listen ¶
Listen takes addr:portmin-portmax and binds to the first available port Example: Listen("localhost:5000-6000", fn)
func ParseFloat32 ¶
func ParseFloat32(v interface{}) float32
ParseFloat32 convert interface to float32.
func ParseFloat64 ¶
func ParseFloat64(v interface{}) float64
ParseFloat64 convert interface to float64.
func ParseSlice ¶
func ParseSlice(v interface{}) []interface{}
func ParseStrSlice ¶
func ParseStrSlice(v []interface{}) []string
ParseStrSlice convert []interface to []string
func SliceChunk ¶ added in v0.0.4
func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})
SliceChunk separates one slice to some sized slice.
func SliceDiff ¶ added in v0.0.4
func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})
SliceDiff returns diff slice of slice1 - slice2.
func SliceFilter ¶ added in v0.0.4
func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})
SliceFilter generates a new slice after filter function.
func SliceIntersect ¶ added in v0.0.4
func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})
SliceIntersect returns slice that are present in all the slice1 and slice2.
func SliceMerge ¶ added in v0.0.4
func SliceMerge(slice1, slice2 []interface{}) (c []interface{})
SliceMerge merges interface slices to one slice.
func SlicePad ¶ added in v0.0.4
func SlicePad(slice []interface{}, size int, val interface{}) []interface{}
SlicePad prepends size number of val into slice.
func SliceRand ¶ added in v0.0.4
func SliceRand(a []interface{}) (b interface{})
SliceRand returns random one from slice.
func SliceRandList ¶ added in v0.0.4
SliceRandList generate an int slice from min to max.
func SliceRandStr ¶ added in v0.0.4
SliceRand returns random one from slice.
func SliceRange ¶ added in v0.0.4
SliceRange generates a new slice from begin to end with step duration of int64 number.
func SliceReduce ¶ added in v0.0.4
func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})
SliceReduce generates a new slice after parsing every value by reduce function
func SliceShuffle ¶ added in v0.0.4
func SliceShuffle(slice []interface{}) []interface{}
SliceShuffle shuffles a slice.
func SliceShuffleInt ¶ added in v0.0.4
SliceShuffleInt shuffles a int slice.
func SliceTwoElem ¶
反射创建切片 (以 .Addr.Interface() 获取指针数据)
func SliceUnique ¶ added in v0.0.4
func SliceUnique(slice []interface{}) (uniqueslice []interface{})
SliceUnique cleans repeated values in slice.
func SplitStrSlice ¶ added in v0.0.4
SplitStrSlice 获取字符串切片
func StrSliceElem ¶
func StrSliceIface ¶ added in v0.0.4
func StrSliceIface(slice []string) (result []interface{})
StrSliceIface 字符串切片转 []interface{}
func StrSliceUnique ¶ added in v0.0.4
StrSliceUnique cleans repeated values in slice.
func StructToDict ¶
func StructToDict(data interface{}) map[string]interface{}
StructToDict 结构体转字典 (不支持嵌套)
Types ¶
type Error ¶
type Error struct { Code int32 `json:"code"` Status string `json:"status"` Detail string `json:"detail"` // contains filtered or unexported fields }
func New ¶
New returns an error with the supplied proto. New also records the stack trace at the point it was called.
func (Error) StackTrace ¶
func (s Error) StackTrace() StackTrace
type Frame ¶
type Frame uintptr
Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.
func (Frame) Format ¶
Format formats the frame according to the fmt.Formatter interface.
%s source file %d source line %n function name %v equivalent to %s:%d
Format accepts flags.go that alter the printing of some verbs, as follows:
%+s function name and path of source file relative to the compile time GOPATH separated by \n\t (<funcname>\n\t<path>) %+v equivalent to %+s:%d
func (Frame) MarshalText ¶
MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.
type StackTrace ¶
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags.go that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.