util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugMode 调试模式
	DebugMode = "debug"
	// TestMode 测试模式
	TestMode = "test"
	// ReleaseMode 正式模式
	ReleaseMode = "release"
	// SessionKeyUserID 存储在session中的键(用户ID)
	SessionKeyUserID = "user_id"
	// ContextKeyUserID 存储上下文中的键(用户ID)
	ContextKeyUserID = "user_id"
	// ContextKeyURLMemo 存储上下文中的键(请求URL说明)
	ContextKeyURLMemo = "url_memo"
	// ContextKeyTraceID 存储上下文中的键(跟踪ID)
	ContextKeyTraceID = "trace_id"
)

Variables

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

定义JSON操作

View Source
var (
	ErrNotFound = errors.New("未找到资源")
)

定义错误

Functions

func ConvertToViewTree

func ConvertToViewTree(treeDatas []map[string]interface{}, labelField, valueField, keyField string) []map[string]interface{}

ConvertToViewTree 转换树形数据为视图树数据

func FromTraceIDContext

func FromTraceIDContext(ctx context.Context) string

FromTraceIDContext 从上下文中获取跟踪ID

func FromUserIDContext

func FromUserIDContext(ctx context.Context) string

FromUserIDContext 从上下文中获取用户ID

func GetLevelCode

func GetLevelCode(orderLevelCodes []string) string

GetLevelCode 获取分级码

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON编码为字符串

func MD5Hash

func MD5Hash(b []byte) string

MD5Hash MD5哈希值

func MD5HashString

func MD5HashString(s string) string

MD5HashString MD5哈希值

func MustUUID

func MustUUID() string

MustUUID 创建一个UUID,如果有错误,则抛出panic

func NewTraceIDContext

func NewTraceIDContext(ctx context.Context, traceID string) context.Context

NewTraceIDContext 创建跟踪ID上下文

func NewUUID

func NewUUID() (string, error)

NewUUID 创建UUID,参考:https://github.com/google/uuid

func NewUserIDContext

func NewUserIDContext(ctx context.Context, userID string) context.Context

NewUserIDContext 创建用户ID上下文

func ParseLevelCodes

func ParseLevelCodes(levelCodes ...string) []string

ParseLevelCodes 解析分级码(去重)

func SHA1Hash

func SHA1Hash(b []byte) string

SHA1Hash SHA1哈希值

func SHA1HashString

func SHA1HashString(s string) string

SHA1HashString SHA1哈希值

func Slice2Tree

func Slice2Tree(sliceDatas []map[string]interface{}, idField, pidField string) []map[string]interface{}

Slice2Tree 将切片数据转换为树形数据

func StructToMap

func StructToMap(s interface{}) map[string]interface{}

StructToMap 将结构体转换为字典

func StructsToMapSlice

func StructsToMapSlice(v interface{}) []map[string]interface{}

StructsToMapSlice 将结构体切片转换为字典切片

func Trim

func Trim(s string) string

Trim 去除空格

Types

type S

type S string

S 字符串类型转换

func (S) Bytes added in v1.1.0

func (s S) Bytes() []byte

Bytes 转换为[]byte

func (S) Float64

func (s S) Float64() float64

Float64 转换为float64

func (S) Int

func (s S) Int() int

Int 转换为int

func (S) Int64

func (s S) Int64() int64

Int64 转换为int64

func (S) String

func (s S) String() string

func (S) ToJSON added in v1.1.0

func (s S) ToJSON(v interface{}) error

ToJSON 转换为JSON

func (S) Uint

func (s S) Uint() uint

Uint 转换为uint

func (S) Uint64

func (s S) Uint64() uint64

Uint64 转换为uint64

type V

type V interface {
	Bytes() []byte
	String() string
	Int64() int64
	Int() int
	Uint() uint
	Float64() float64
	Uint64() uint64
	Bool() bool
}

V interface{}类型转换

func T

func T(v interface{}) V

T 获取转换interface{}

Jump to

Keyboard shortcuts

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