util

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderRev           = "X-Resource-Revision"
	CtxGlobal           = "global"
	CtxNocache          = "noCache"
	CtxCacheOnly        = "cacheOnly"
	CtxRequestRevision  = "requestRev"
	CtxResponseRevision = "responseRev"
)
View Source
const (
	CtxDomain        = "domain"
	CtxProject       = "project"
	CtxTargetDomain  = "target-domain"
	CtxTargetProject = "target-project"
)
View Source
const DASH = "-"

Variables

This section is empty.

Functions

func BytesToStringWithNoCopy

func BytesToStringWithNoCopy(bytes []byte) string

func CloneContext

func CloneContext(ctx context.Context) context.Context

func FileLastName

func FileLastName(file string) string

func FormatFuncName

func FormatFuncName(f string) string

func FromContext

func FromContext(ctx context.Context, key string) interface{}

func FromDomainProject

func FromDomainProject(domainProject string) (domain, project string)

func FromMetadata

func FromMetadata(ctx context.Context, key string) string

func FuncName

func FuncName(f interface{}) string

func GenerateUUID

func GenerateUUID() string

func GetCaller

func GetCaller(skip int) (string, string, int, bool)

func GetEnvInt

func GetEnvInt(name string, def int) int

func GetEnvString

func GetEnvString(name string, def string) string

func GetIPFromContext

func GetIPFromContext(ctx context.Context) string

func GetProcCPUUsage

func GetProcCPUUsage() (pt float64, ct float64)

func GetRealIP

func GetRealIP(r *http.Request) string

func HostName

func HostName() (hostname string)

func InetAton

func InetAton(ip string) (ipnr uint32)

func InetNtoIP

func InetNtoIP(ipnr uint32) net.IP

func InetNtoa

func InetNtoa(ipnr uint32) string

func Int16ToInt64

func Int16ToInt64(bs []int16) (in int64)

func IsBigEndian

func IsBigEndian() bool

func IsLittleEndian

func IsLittleEndian() bool

func IsVersionOrHealthPattern

func IsVersionOrHealthPattern(pattern string) bool

func ListToMap

func ListToMap(list []string) map[string]struct{}

func MapToList

func MapToList(dict map[string]struct{}) []string

func ParseDomain

func ParseDomain(ctx context.Context) string

func ParseDomainProject

func ParseDomainProject(ctx context.Context) string

func ParseEndpoint

func ParseEndpoint(ep string) (string, error)

func ParseProject

func ParseProject(ctx context.Context) string

func ParseRequestURL

func ParseRequestURL(r *http.Request) string

func ParseTargetDomain

func ParseTargetDomain(ctx context.Context) string

func ParseTargetDomainProject

func ParseTargetDomainProject(ctx context.Context) string

func ParseTargetProject

func ParseTargetProject(ctx context.Context) string

func PathExist

func PathExist(path string) bool

func ResetTimer

func ResetTimer(timer *time.Timer, d time.Duration)

do not call after drain timer.C channel

func SafeCloseChan

func SafeCloseChan(c chan struct{})

func SetContext

func SetContext(ctx context.Context, key string, val interface{}) context.Context

func SetDomain

func SetDomain(ctx context.Context, domain string) context.Context

func SetDomainProject

func SetDomainProject(ctx context.Context, domain string, project string) context.Context

func SetProject

func SetProject(ctx context.Context, project string) context.Context

func SetRequestContext

func SetRequestContext(r *http.Request, key string, val interface{}) *http.Request

func SetTargetDomain

func SetTargetDomain(ctx context.Context, domain string) context.Context

func SetTargetDomainProject

func SetTargetDomainProject(ctx context.Context, domain string, project string) context.Context

func SetTargetProject

func SetTargetProject(ctx context.Context, project string) context.Context

func Sizeof

func Sizeof(obj interface{}) uint64

func SliceHave

func SliceHave(arr []string, str string) bool

func StringJoin

func StringJoin(args []string, sep string) string

func StringTRUE

func StringTRUE(s string) bool

func StringToBytesWithNoCopy

func StringToBytesWithNoCopy(s string) []byte

func ToDomainProject

func ToDomainProject(domain, project string) (domainProject string)

Types

type ConcurrentMap

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

func NewConcurrentMap

func NewConcurrentMap(_ int) *ConcurrentMap

func (*ConcurrentMap) Clear

func (cm *ConcurrentMap) Clear()

func (*ConcurrentMap) Fetch

func (cm *ConcurrentMap) Fetch(key interface{}, f func() (interface{}, error)) (v interface{}, err error)

func (*ConcurrentMap) ForEach

func (cm *ConcurrentMap) ForEach(f func(item MapItem) (next bool))

func (*ConcurrentMap) Get

func (cm *ConcurrentMap) Get(key interface{}) (val interface{}, b bool)

func (*ConcurrentMap) Put

func (cm *ConcurrentMap) Put(key, val interface{})

func (*ConcurrentMap) PutIfAbsent

func (cm *ConcurrentMap) PutIfAbsent(key, val interface{}) (exist interface{})

func (*ConcurrentMap) Remove

func (cm *ConcurrentMap) Remove(key interface{})

func (*ConcurrentMap) Size

func (cm *ConcurrentMap) Size() (s int)

type IPPort

type IPPort struct {
	IP   string
	Port uint16
}

func ParseIPPort

func ParseIPPort(addr string) IPPort

type JSONObject

type JSONObject map[string]interface{}

func NewJSONObject

func NewJSONObject() JSONObject

func (JSONObject) Bool

func (c JSONObject) Bool(k interface{}, def bool) bool

func (JSONObject) Int

func (c JSONObject) Int(k interface{}, def int) int

func (JSONObject) Object

func (c JSONObject) Object(k interface{}) JSONObject

func (JSONObject) Set

func (c JSONObject) Set(k interface{}, v interface{}) JSONObject

func (JSONObject) String

func (c JSONObject) String(k interface{}, def string) string

type MapItem

type MapItem struct {
	Key   interface{}
	Value interface{}
}

type Node

type Node struct {
	Res interface{}
	// contains filtered or unexported fields
}

type ReflectObject

type ReflectObject struct {
	// full name
	FullName string
	Type     reflect.Type
	// if type is not struct, Fields is nil
	Fields []reflect.StructField
}

func Reflect

func Reflect(obj interface{}) *ReflectObject

func (*ReflectObject) Name

func (o *ReflectObject) Name() string

Name returns a short name of the object type

type Reflector

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

func (*Reflector) Load

func (r *Reflector) Load(obj interface{}) *ReflectObject

type StringContext

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

func NewStringContext

func NewStringContext(ctx context.Context) *StringContext

func (*StringContext) Deadline

func (c *StringContext) Deadline() (deadline time.Time, ok bool)

func (*StringContext) Done

func (c *StringContext) Done() <-chan struct{}

func (*StringContext) Err

func (c *StringContext) Err() error

func (*StringContext) SetKV

func (c *StringContext) SetKV(key string, val interface{})

func (*StringContext) Value

func (c *StringContext) Value(key interface{}) interface{}

type Tree

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

The Tree is binary sort Tree

func NewTree

func NewTree(isAddToLeft func(node *Node, addRes interface{}) bool) *Tree

func (*Tree) AddNode

func (t *Tree) AddNode(res interface{}) *Node

add res into Tree

func (*Tree) GetRoot

func (t *Tree) GetRoot() *Node

func (*Tree) InOrderTraversal

func (t *Tree) InOrderTraversal(n *Node, handle func(res interface{}) error) error

middle oder traversal, handle is the func that deals with the res, n is the start node to traversal

Jump to

Keyboard shortcuts

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