xtools

package
v0.0.0-...-80fcaa9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//User-Agent
	USER_AGENT string = "ares/v1"
)

Variables

This section is empty.

Functions

func AddTask

func AddTask(spec string, fn TaskHandler, name ...string)

func BHex2Num

func BHex2Num(str string, n int) (int64, error)

func BindYAML

func BindYAML(path string, bind interface{}) error

BindYaml "gopkg.in/yaml.v2"

func Caller

func Caller(calldepth int, short bool) string

func Codes

func Codes(err error) codes.Code

func Contain

func Contain(key interface{}, val interface{}) bool

Contain Contain

func DeepCopy

func DeepCopy(src interface{}, out interface{}) error

func ErrDetail

func ErrDetail(err error) string

func ErrMsg

func ErrMsg(err error) string

String err to string

func ErrString

func ErrString(err error) string

String err to string

func FileExists

func FileExists(path string) bool

FileExists FileExists

func FloatVal

func FloatVal(data string) (float64, bool)

FloatVal parse float

func FromXErr

func FromXErr(err error) *status.Status

func GBKToUTF8

func GBKToUTF8(data string) (string, error)

GbkToUtf8 GbkToUtf8

func GUID

func GUID() string

GUID Guid

func Get

func Get(ctx context.Context, apiurl string, data map[string]string, second int, retry int) (string, error)

Get Get

func Has

func Has(key interface{}, val ...interface{}) bool

Has 数组中包含是否包含查找的对象

func HashID

func HashID(id string, m int64) int64

HashID Hash

func IntVal

func IntVal(data string) (int64, bool)

IntVal parse int

func InternalErr

func InternalErr(serr error, msg string, where ...bool) error

func JSONMarshal

func JSONMarshal(data interface{}) (string, error)

func JSONToStr

func JSONToStr(dstr interface{}) string

JSONToStr JsonToStr

func MErr

func MErr(serr error, code codes.Code, msg string, where ...bool) error

func MergeUrl

func MergeUrl(uri string, param map[string]string) string

MergeUrl 合并URL参数

func NumToBHex

func NumToBHex(num, n int64) (string, error)

func ObjectIDCounter

func ObjectIDCounter(w int) string

func Post

func Post(ctx context.Context, apiurl string, data map[string]string, second int, retry int) (string, error)

Post Post urlencode

func PostJSON

func PostJSON(ctx context.Context, apiurl string, data map[string]interface{}, second int, retry int) (string, error)

PostJSON Post json

func RandID

func RandID(width int) string

RandID 随机ID

func StartTask

func StartTask()

func StopTask

func StopTask()

func SubStr

func SubStr(str string, begin, length int) (substr string)

SubStr SubStr

func ToJSON

func ToJSON(dstr string, data interface{}) error

ToJson ToJson

func ToStr

func ToStr(dval interface{}) string

ToStr ToStr

func ToYAML

func ToYAML(data interface{}) (string, error)

func UTF8ToGBK

func UTF8ToGBK(data string) (string, error)

UTF8ToGBK UTF8ToGBK

func UrlDecode

func UrlDecode(data string) map[string]string

UrlDecode UrlDecode

func UrlEncode

func UrlEncode(data map[string]string) string

UrlEncode UrlEncode

func WrapErr

func WrapErr(ctx context.Context, err error) error

func XErr

func XErr(code codes.Code, msg string, where ...bool) error

func XMLToJSON

func XMLToJSON(str string, obj interface{}) error

func YAMLToJSON

func YAMLToJSON(str string, obj interface{}) error

Types

type Broadcast

type Broadcast interface {
	Close() error
	Push(data string) error
	Subscriber() string
}

type BroadcastItem

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

func (*BroadcastItem) Close

func (c *BroadcastItem) Close() error

func (*BroadcastItem) Push

func (c *BroadcastItem) Push(data string) error

func (*BroadcastItem) Subscriber

func (c *BroadcastItem) Subscriber() string

type BroadcastManager

type BroadcastManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBroadcastManager

func NewBroadcastManager(cap int) *BroadcastManager

func (*BroadcastManager) Get

func (c *BroadcastManager) Get() (Broadcast, error)

func (*BroadcastManager) Len

func (c *BroadcastManager) Len() int

func (*BroadcastManager) Push

func (c *BroadcastManager) Push(data string) error

type ES

type ES map[string]string

func StructToStringMap

func StructToStringMap(data interface{}) ES

StructToStringMap struct => map[string]string

type FieldTag

type FieldTag struct {
	Value string   `json:"value"`
	Ext   []string `json:"ext"`
}

func NewTag

func NewTag(tag string) FieldTag

func (*FieldTag) Encode

func (h *FieldTag) Encode() string

func (*FieldTag) HasExt

func (h *FieldTag) HasExt(ext ...string) bool

type ScoreTree

type ScoreTree struct {
	MaxScore int
	Mem      []int64 // 树使用的数组
	sync.RWMutex
}

ScoreTree 使用树状数组实现

func NewScoreTree

func NewScoreTree(maxScore int) *ScoreTree

func (*ScoreTree) Add

func (tree *ScoreTree) Add(n int, value int64)

给对应的积分增加人数

func (*ScoreTree) GetOrder

func (tree *ScoreTree) GetOrder(score int) int64

获取排名 调用方法GetOrder

func (*ScoreTree) GetTotal

func (tree *ScoreTree) GetTotal() int64

获取参与排名总人数

func (*ScoreTree) Query

func (tree *ScoreTree) Query(n int) int64

获取[0, n]的总和

type TaskHandler

type TaskHandler func() error

Jump to

Keyboard shortcuts

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