Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToInt32(buf []byte) int32
- func BytesToInt64(buf []byte) int64
- func CPU() *psutilCPU
- func ConvertByte2String(b []byte, charset Charset) string
- func DecodeAESWithKey(key, str string) string
- func Disk() *psutilDisk
- func EncodeAESWithKey(key, str string) string
- func EqualAES(key, raw, hash string) bool
- func Exec(arg ...string) ([]byte, error)
- func ExecStr(args string) ([]byte, error)
- func Filename(fullpath string) string
- func FmtTimestamp(ts int64) time.Time
- func GetPkg(name string) template.FuncMap
- func Host() *psutilHost
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- func IsExist(path string) bool
- func IsURL(urlStr string) bool
- func JsonStr(v JsonValue) string
- func MD5(str string) string
- func Mem() *psutilMem
- func Mkdirs(path string) error
- func Net() *psutilNet
- func NowTimestamp() int64
- func NowTimestampByString() string
- func OpenConf(path string, opts ...viper.Option) (*viper.Viper, error)
- func PathIsExist(path string) (bool, error)
- func Pathf(path string) string
- func Prinf(opt PrintfOpt, title []string, rows [][]string)
- func RandString(n int) string
- func RandomPort() (int, error)
- func ReadLineFromFile(file string, filter func(string) string) ([]byte, error)
- func ReadLineFromString(str string, filter func(string) string) ([]byte, error)
- func ReadStraemFromFile(file string) ([]byte, error)
- func SHA256(str string) string
- func SafeBatchMkdirs(dirs []string) error
- func SafeMkdirs(path string) error
- func SafeWriteFile(file string, data []byte) error
- func SetBytesMode(_type bool)
- func SimilarText(first, second string, percent *float64) int
- func Title(str string) string
- func WriteFile(file string, data []byte) error
- type ByteWalk
- type BytesDecode
- type BytesEncode
- type BytesTransfomer
- type CSSLiteralGenerator
- type Charset
- type CheckedVersion
- type Comparable
- type Duration
- func (d *Duration) AddHour(i float64)
- func (d *Duration) AddMinute(i float64)
- func (d *Duration) AddSecond(i float64)
- func (d *Duration) Clone() *Duration
- func (d *Duration) Format(sep string) string
- func (d *Duration) Hour() int
- func (d *Duration) Interval() string
- func (d *Duration) String() string
- func (d *Duration) SubHour(i float64)
- func (d *Duration) SubMinute(i float64)
- func (d *Duration) SubSecond(i float64)
- type JsonArray
- type JsonBool
- type JsonNull
- type JsonNumber
- type JsonObject
- type JsonString
- type JsonValue
- type LoadBalancer
- type LuaLiteralGenerator
- func (LuaLiteralGenerator) Eq(a, b string) string
- func (LuaLiteralGenerator) GetVar(name string) string
- func (LuaLiteralGenerator) IRange(kv, t string) string
- func (LuaLiteralGenerator) Range(kv, t string) string
- func (LuaLiteralGenerator) SetVar(name, value string) string
- func (LuaLiteralGenerator) StrJoin(name string, value ...string) string
- func (gen LuaLiteralGenerator) Var(name, value string) string
- type Platform
- type Plugin
- type PluginFunc
- type PosixPlugin
- type PosixPluginFunc
- type PrintfOpt
- type SafeMap
- func (m *SafeMap[T]) Delete(k string)
- func (m *SafeMap[T]) Get(k string) (T, bool)
- func (m *SafeMap[T]) Keys() (keys []string)
- func (m *SafeMap[T]) Range(handle func(k string, v T) bool)
- func (m *SafeMap[T]) SafeDelete(k string)
- func (m *SafeMap[T]) SafeGet(k string) (T, bool)
- func (m *SafeMap[T]) SafeRange(handle func(k string, v T) bool)
- func (m *SafeMap[T]) SafeSet(k string, v T)
- func (m *SafeMap[T]) Set(k string, v T)
- type Template
- func (tmpl *Template) LazyLoadFiles() *Template
- func (tmpl *Template) LazyLoadPkgs() *Template
- func (tmpl *Template) LoadFiles(filename ...string) *Template
- func (tmpl *Template) LoadPkgs(pkgs ...string) *Template
- func (tmpl *Template) OnceParse(text string, data any) (string, error)
- func (tmpl *Template) OnceParseFile(data any, filenames ...string) (string, error)
- func (tmpl *Template) Preprocess(doc string) string
- func (tmpl *Template) Run(doc string) (string, error)
- type TemplateLinker
- type TemplateLiteralGenerator
- func (TemplateLiteralGenerator) Batch(cmd ...string) string
- func (TemplateLiteralGenerator) Block(name, scope, expression string) string
- func (TemplateLiteralGenerator) Call(name string, params ...string) string
- func (TemplateLiteralGenerator) Define(name, expression string) string
- func (TemplateLiteralGenerator) Get(name string) string
- func (TemplateLiteralGenerator) If(conditions []string, expressions []string) string
- func (TemplateLiteralGenerator) Pipe() string
- func (TemplateLiteralGenerator) Range(condition, expression string) string
- func (TemplateLiteralGenerator) Ref(name string) string
- func (TemplateLiteralGenerator) Scope(cmd string) string
- func (TemplateLiteralGenerator) Str(str string) string
- func (TemplateLiteralGenerator) Template(name string) string
- func (TemplateLiteralGenerator) Var(name, value string) string
- func (TemplateLiteralGenerator) With(condition, expression string) string
- type TemplateOpt
- type Time
- func (tm *Time) AddDate(years, months, days int)
- func (tm Time) Clone() *Time
- func (tm *Time) Day() int
- func (tm *Time) Diff(t *Time) *Duration
- func (tm *Time) DiffNow() *Duration
- func (tm *Time) Format(layout string) string
- func (tm *Time) Month() int
- func (tm *Time) String() string
- func (tm *Time) Year() int
- type Timer
- type WeightedRandom
Constants ¶
const ( UTF8 = Charset("UTF-8") GB18030 = Charset("GB18030") )
const ( BigEndian = true LittleEndian = false ByteSize = 1 BoolSize = 1 Int16Size = 2 * ByteSize Int32Size = 4 * ByteSize Int64Size = 8 * ByteSize Float32Size = 4 * ByteSize Float64Size = 8 * ByteSize ByteType = iota BoolType IntType Int16Type Int32Type Int64Type Float32Type Float64Type StringType )
const ( NONE = iota UPPER DOWN )
Variables ¶
var ( ErrArgsTooLittle = errors.New("arguments is too little") ErrInvalidModuleName = errors.New("invalid module name") ErrDumplicateJobName = errors.New("dumplicate job name") ErrCreateSession = errors.New("fail to create session") ErrExecuteCommand = errors.New("fail to execute command") ErrAllocTerm = errors.New("fail to allocate term") ErrAllocShell = errors.New("fail to allocate shell") // net ErrInvalidPort = errors.New("invalid port") ErrInvalidURL = errors.New("invalid url") ErrInvalidMethod = errors.New("invalid method") ErrBadCreateRequest = errors.New("error createing request") ErrBadSendRequest = errors.New("error sending request") ErrNoSupportPlatform = errors.New("not support the platform") ErrNoSupportHardward = errors.New("not support the hardward") ErrInvalidPath = errors.New("invalid path") ErrBadCreateDir = errors.New("fail to create dir") ErrBadCreateFile = errors.New("fail to create file") ErrInvalidFile = errors.New("invalid file") ErrFileNotExist = errors.New("file not exist") ErrPathNotFound = errors.New("path not found") ErrFileExist = errors.New("file exist") // yock plugin ErrPluginExist = errors.New("plugin exist already") ErrDomainExist = errors.New("domain exist already") ErrAliasExist = errors.New("alias exist already") ErrUserNotFound = errors.New("user not found") ErrPermDenied = errors.New("permission denied") ErrOutRange = errors.New("out of range") ErrGeneral = errors.New("err happen") )
var ( JsonTrue = NewJsonBool(true) JsonFalse = NewJsonBool(false) JsonNil = NewJsonNull() )
var ( // YockBuild has two values, dev and release, // which correspond to two different modes. // // The value YOCK_PATH under dev is taken from main.go under the /ctl. // If it is in release mode, the actual location of the executable file shall prevail. // // This value will be changed by -ldflag at compile time. Details to see /auto/build.lua. YockBuild = "dev" YockVersion = "" )
var ( // WorkSpace is the .yock path in the UserHome // // You can think of it as yock's global workspace // for storing user's information. WorkSpace string PluginPath string DriverPath string // executable file path YockPath string )
Functions ¶
func BytesToInt32 ¶
func BytesToInt64 ¶
func ConvertByte2String ¶
func DecodeAESWithKey ¶
func EncodeAESWithKey ¶
func Exec ¶
Exec automatically fit in os enviroment to execute command. windows 10+ -> powershell, others -> cmd; linux, darwin -> /bin/bash
func FmtTimestamp ¶
FmtTimestamp return a time string whom format is 2006-01-02
func Int32ToBytes ¶
func Int64ToBytes ¶
func NowTimestampByString ¶
func NowTimestampByString() string
NowTimestamp returm current timestamp string
func PathIsExist ¶
PathIsExist judge whether path exist. If exist, return true.
func Pathf ¶
Pathf to format path
@/abc => {WorkSpace}/abc (WorkSpace = UserHome + .yock)
~/abc => {YockPath}/abc (YockPath = executable file path)
func ReadLineFromFile ¶
ReadStraemFromFile return data to be filter from specify file
func ReadLineFromString ¶
ReadStraemFromFile return data to be filter from string
func ReadStraemFromFile ¶
ReadStraemFromFile return total data from specify file
func SafeBatchMkdirs ¶
SafeBatchMkdirs recurse to create dirs when path isn't exist
func SafeMkdirs ¶
SafeMkdirs recurse to create path when path isn't exist
func SafeWriteFile ¶
WriteFile write data or create file to write data according to file when file isn't exist
func SetBytesMode ¶
func SetBytesMode(_type bool)
func SimilarText ¶
Powered by github.com/syyongx/php2go
Types ¶
type ByteWalk ¶
type ByteWalk struct {
// contains filtered or unexported fields
}
func NewByteWalk ¶
type BytesDecode ¶
type BytesDecode struct {
// contains filtered or unexported fields
}
func NewBytesDecode ¶
func NewBytesDecode(_type bool) BytesDecode
func (BytesDecode) BytesToFloat32 ¶
func (decode BytesDecode) BytesToFloat32(buf []byte) float32
func (BytesDecode) BytesToFloat64 ¶
func (decode BytesDecode) BytesToFloat64(buf []byte) float64
func (BytesDecode) BytesToInt16 ¶
func (decode BytesDecode) BytesToInt16(buf []byte) int16
func (BytesDecode) BytesToInt32 ¶
func (decode BytesDecode) BytesToInt32(buf []byte) int32
func (BytesDecode) BytesToInt64 ¶
func (decode BytesDecode) BytesToInt64(buf []byte) int64
type BytesEncode ¶
type BytesEncode struct {
// contains filtered or unexported fields
}
func NewBytesEncode ¶
func NewBytesEncode(_type bool) BytesEncode
func (BytesEncode) Float32ToBytes ¶
func (encode BytesEncode) Float32ToBytes(f float32) []byte
func (BytesEncode) Float64ToBytes ¶
func (encode BytesEncode) Float64ToBytes(f float64) []byte
func (BytesEncode) Int16ToBytes ¶
func (encode BytesEncode) Int16ToBytes(i int16) []byte
func (BytesEncode) Int32ToBytes ¶
func (encode BytesEncode) Int32ToBytes(i int32) []byte
func (BytesEncode) Int64ToBytes ¶
func (encode BytesEncode) Int64ToBytes(i int64) []byte
type BytesTransfomer ¶
type BytesTransfomer struct { BytesEncode BytesDecode }
var ByteTransfomer BytesTransfomer
func (BytesTransfomer) AutoToBytes ¶
func (transfomer BytesTransfomer) AutoToBytes(data any) []byte
func (BytesTransfomer) AutoToType ¶
func (transfomer BytesTransfomer) AutoToType(raw []byte, _type int) any
type CSSLiteralGenerator ¶
type CSSLiteralGenerator struct{}
type CheckedVersion ¶
type CheckedVersion struct {
// contains filtered or unexported fields
}
func NewCheckedVersion ¶
func NewCheckedVersion(version string) *CheckedVersion
func (*CheckedVersion) Compare ¶
func (want *CheckedVersion) Compare(got *CheckedVersion) bool
type Comparable ¶
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
func ParseDuration ¶
type JsonArray ¶
type JsonArray struct {
// contains filtered or unexported fields
}
func NewJsonArray ¶
type JsonBool ¶
type JsonBool struct {
// contains filtered or unexported fields
}
func NewJsonBool ¶
type JsonNumber ¶
type JsonNumber struct {
// contains filtered or unexported fields
}
func NewJsonNumber ¶
func NewJsonNumber(v int64) JsonNumber
func (JsonNumber) Value ¶
func (obj JsonNumber) Value() string
type JsonObject ¶
type JsonObject struct {
// contains filtered or unexported fields
}
func NewJsonObject ¶
func NewJsonObject(v map[string]JsonValue) *JsonObject
func (*JsonObject) Value ¶
func (obj *JsonObject) Value() string
type JsonString ¶
type JsonString struct {
// contains filtered or unexported fields
}
func NewJsonString ¶
func NewJsonString(v string) JsonString
func (JsonString) Value ¶
func (obj JsonString) Value() string
type JsonValue ¶
type JsonValue interface {
Value() string
}
JsonValue is an interface to abstract object of json type.
type LoadBalancer ¶
type LoadBalancer[T any] interface { // Next returns an element and its index. // If error, returns -1. Next() (T, int) // Up increases the probability of element to be specified Up(idx int) // Down decreases the probability of element to be specified Down(idx int) Put(e T) Del(idx int) Weights() []float64 }
type LuaLiteralGenerator ¶
type LuaLiteralGenerator struct {
TemplateLiteralGenerator
}
func (LuaLiteralGenerator) Eq ¶
func (LuaLiteralGenerator) Eq(a, b string) string
func (LuaLiteralGenerator) GetVar ¶
func (LuaLiteralGenerator) GetVar(name string) string
func (LuaLiteralGenerator) IRange ¶
func (LuaLiteralGenerator) IRange(kv, t string) string
func (LuaLiteralGenerator) Range ¶
func (LuaLiteralGenerator) Range(kv, t string) string
func (LuaLiteralGenerator) SetVar ¶
func (LuaLiteralGenerator) SetVar(name, value string) string
func (LuaLiteralGenerator) StrJoin ¶
func (LuaLiteralGenerator) StrJoin(name string, value ...string) string
func (LuaLiteralGenerator) Var ¶
func (gen LuaLiteralGenerator) Var(name, value string) string
type Plugin ¶
type Plugin interface { // Func return PluginFunc which is an abstract function to be exported dynamic library // according to funcName. You can use PluginFunc to call function from dynamic library. Func(string) (PluginFunc, error) }
Plugin is an interface to abstract dynamic library (dll, dylib, so)
type PluginFunc ¶
type PluginFunc interface { // Call return excuted result from dynamic library Call(...uintptr) (uintptr, error) // Addr returns the address of function pointer Addr() uintptr }
PluginFunc is an interface to abstract function to be exported dynamic library
type PosixPlugin ¶
type PosixPlugin struct {
// contains filtered or unexported fields
}
func (*PosixPlugin) Func ¶
func (pp *PosixPlugin) Func(name string) (PluginFunc, error)
Func return PluginFunc which is an abstract function to be exported dynamic library according to funcName. You can use PluginFunc to call function from dynamic library.
type PosixPluginFunc ¶
type PosixPluginFunc struct {
// contains filtered or unexported fields
}
func (*PosixPluginFunc) Addr ¶
func (ppf *PosixPluginFunc) Addr() uintptr
Call return excuted result from dynamic library
type SafeMap ¶
type SafeMap[T any] struct { // contains filtered or unexported fields }
SafeMap is a simple alternative version of sync.map, designed specifically for SignalStream. Provides unlocked (unsafe) and locked (safe) to operate map to meet special scenarios to improve performance.
func NewSafeMap ¶
func (*SafeMap[T]) Get ¶
Get directly obtains the value of the specified k without locking. If the value doesn't exist, the second parameter returns false, and vice versa.
func (*SafeMap[T]) Range ¶
Range ranges map without locking. You can set callback to implement demand.
func (*SafeMap[T]) SafeDelete ¶
func (*SafeMap[T]) SafeGet ¶
SafeGet locks to get the value of the specified k. If the value doesn't exist, the second parameter returns false, and vice versa.
func (*SafeMap[T]) SafeRange ¶
SafeRange locks to range map. You can set callback to implement demand.
type Template ¶
func NewTemplate ¶
func NewTemplate(opt ...TemplateOpt) *Template
func (*Template) LazyLoadFiles ¶
func (*Template) LazyLoadPkgs ¶
func (*Template) OnceParseFile ¶
func (*Template) Preprocess ¶
type TemplateLinker ¶
func (*TemplateLinker) Load ¶
func (ld *TemplateLinker) Load(files ...string) string
func (*TemplateLinker) Using ¶
func (ld *TemplateLinker) Using(pkgs ...string) string
type TemplateLiteralGenerator ¶
type TemplateLiteralGenerator struct{}
func (TemplateLiteralGenerator) Batch ¶
func (TemplateLiteralGenerator) Batch(cmd ...string) string
func (TemplateLiteralGenerator) Block ¶
func (TemplateLiteralGenerator) Block(name, scope, expression string) string
func (TemplateLiteralGenerator) Call ¶
func (TemplateLiteralGenerator) Call(name string, params ...string) string
func (TemplateLiteralGenerator) Define ¶
func (TemplateLiteralGenerator) Define(name, expression string) string
func (TemplateLiteralGenerator) Get ¶
func (TemplateLiteralGenerator) Get(name string) string
func (TemplateLiteralGenerator) If ¶
func (TemplateLiteralGenerator) If(conditions []string, expressions []string) string
func (TemplateLiteralGenerator) Pipe ¶
func (TemplateLiteralGenerator) Pipe() string
func (TemplateLiteralGenerator) Range ¶
func (TemplateLiteralGenerator) Range(condition, expression string) string
func (TemplateLiteralGenerator) Ref ¶
func (TemplateLiteralGenerator) Ref(name string) string
func (TemplateLiteralGenerator) Scope ¶
func (TemplateLiteralGenerator) Scope(cmd string) string
func (TemplateLiteralGenerator) Str ¶
func (TemplateLiteralGenerator) Str(str string) string
func (TemplateLiteralGenerator) Template ¶
func (TemplateLiteralGenerator) Template(name string) string
func (TemplateLiteralGenerator) Var ¶
func (TemplateLiteralGenerator) Var(name, value string) string
func (TemplateLiteralGenerator) With ¶
func (TemplateLiteralGenerator) With(condition, expression string) string
type TemplateOpt ¶
type TemplateOpt struct {
// contains filtered or unexported fields
}
type WeightedRandom ¶
type WeightedRandom[T any] struct { // contains filtered or unexported fields }
func NewWeightedRandom ¶
func NewWeightedRandom[T any]( elements []T, policy ...func(weights []float64) float64) *WeightedRandom[T]
func (*WeightedRandom[T]) Del ¶
func (wr *WeightedRandom[T]) Del(idx int)
func (*WeightedRandom[T]) Down ¶
func (wr *WeightedRandom[T]) Down(idx int)
Down decreases the probability of element to be specified
func (*WeightedRandom[T]) Next ¶
func (wr *WeightedRandom[T]) Next() (T, int)
Next returns an element and its index. If error, returns -1.
func (*WeightedRandom[T]) Put ¶
func (wr *WeightedRandom[T]) Put(e T)
func (*WeightedRandom[T]) Up ¶
func (wr *WeightedRandom[T]) Up(idx int)
Up increases the probability of element to be specified
func (*WeightedRandom[T]) Weights ¶
func (wr *WeightedRandom[T]) Weights() []float64