Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertByte2String(byte []byte, charset Charset) string
- func DecodeAESWithKey(key, str string) string
- 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 FetchFile(src, dst string) (int64, error)
- func Filename(fullpath string) string
- func FirstLower(s string) string
- func FirstUpper(s string) string
- func FmtTimestamp(ts int64) string
- func InitLogger(conf LoggerOpt) error
- func InitLoggerWithDefault() error
- func IsExist(path string) bool
- func IsURL(urlStr string) bool
- func JsonStr(v JsonValue) string
- func MD5(str string) string
- func Mkdirs(path string) error
- func MoveFile(src, dst string) error
- func NewEnv[T any](opt EnvOpt[T]) *T
- func NowTimestamp() int64
- func NowTimestampByString() string
- func OpenConf(name, _type, dir string, opts ...viper.Option) *viper.Viper
- func OpenConfFromPath(path string, opts ...viper.Option) *viper.Viper
- func PathIsExist(path string) (bool, error)
- 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 TrimMultiSpace(s string) string
- func Unzip(src, dst string) error
- func WriteFile(file string, data []byte) error
- func Zip(zipPath string, paths ...string) error
- type BaseEnv
- type ByteWalk
- type BytesDecode
- type BytesEncode
- type BytesTransfomer
- type CFArray
- type CFBool
- type CFData
- type CFDictionary
- type CFNone
- type CFNumber
- type CFReal
- type CFString
- type CFUID
- type CFValue
- type Charset
- type CheckedVersion
- type EnvOpt
- type EnvVar
- type EnvVarLoadOpt
- type JsonArray
- type JsonBool
- type JsonNull
- type JsonNumber
- type JsonObject
- type JsonString
- type JsonValue
- type LoggerOpt
- type MetaArr
- type MetaMap
- type MetaTable
- type MetaValue
- type Platform
- type PlistFile
- func (pf *PlistFile) Append(value any) error
- func (pf *PlistFile) Backup() error
- func (pf *PlistFile) Free()
- func (pf *PlistFile) GetArr() CFArray
- func (pf *PlistFile) GetArrByField(field string) CFArray
- func (pf *PlistFile) GetBaseValue() CFValue
- func (pf *PlistFile) GetDict() CFDictionary
- func (pf *PlistFile) GetValue(key string) CFValue
- func (pf *PlistFile) Len() int
- func (pf *PlistFile) SafeSet(key string, value any) error
- func (pf *PlistFile) Set(value any)
- func (pf *PlistFile) SetByField(field string, value CFValue) error
- func (pf *PlistFile) SetByIdx(idx int, value any) error
- func (pf *PlistFile) Write() error
- type Plugin
- type PluginFunc
- type PosixEnvVar
- func (env *PosixEnvVar) Export(file string) error
- func (env *PosixEnvVar) Load(opt EnvVarLoadOpt) error
- func (env *PosixEnvVar) Print()
- func (env *PosixEnvVar) SafeSet(k string, v any) error
- func (env *PosixEnvVar) SafeSetL(k, v string) error
- func (env *PosixEnvVar) Set(k string, v any) error
- func (env *PosixEnvVar) SetL(k, v string) error
- func (env *PosixEnvVar) SetPath(path string) error
- func (env *PosixEnvVar) Unset(k string) error
- type PosixMetaTable
- func (tbl *PosixMetaTable) Backup() error
- func (tbl *PosixMetaTable) Close()
- func (tbl *PosixMetaTable) CreateSubTable(name string) MetaTable
- func (tbl *PosixMetaTable) GetValue(v string) MetaValue
- func (tbl *PosixMetaTable) SafeSetValue(v MetaValue)
- func (tbl *PosixMetaTable) SetValue(v MetaValue)
- func (tbl *PosixMetaTable) Write() error
- type PosixPlugin
- type PosixPluginFunc
- type PrintfOpt
- type ReflectDict
- type ReflectObject
- type TypeMeta
Constants ¶
const ( NONE = iota UPPER DOWN )
const ( BlankConf = `workdir: ""` ConfFile = "conf.yaml" )
const ( CF_DICT = iota CF_ARR CF_STR CF_NUM CF_BOOL CF_DATA CF_UID CF_REAL CF_NONE )
const ( UTF8 = Charset("UTF-8") // GB18030 support Chinese encoding GB18030 = Charset("GB18030") BigEndian = true LittleEndian = false ByteSize = 1 Int16Size = 2 * ByteSize Int32Size = 4 * ByteSize Int64Size = 8 * ByteSize Float32Size = 4 * ByteSize Float64Size = 8 * ByteSize ByteType = iota IntType Int16Type Int32Type Int64Type Float32Type Float64Type StringType )
const DefaultLogPath = "/log"
Variables ¶
var ( JsonTrue = NewJsonBool(true) JsonFalse = NewJsonBool(false) JsonNil = NewJsonNull() )
Functions ¶
func ConvertByte2String ¶
ConvertByte2String return encoding string, which main effect to support unicode bytes, for example Chinese.
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 FirstLower ¶
FirstLower return string in which the first letter is lowercase.
func FirstUpper ¶
FirstUpper return string in which the first letter is uppercase.
func FmtTimestamp ¶
FmtTimestamp return a time string whom format is 2006-01-02
func InitLogger ¶
func InitLoggerWithDefault ¶
func InitLoggerWithDefault() error
func NewEnv ¶
NewEnv to init BaseEnv and return Payload pointer which will be initialized from specify configure file in opt.
func NowTimestampByString ¶
func NowTimestampByString() string
NowTimestamp returm current timestamp string
func OpenConf ¶
OpenConf unmarshal file which located in disk to memory according to name, type, dir
func OpenConfFromPath ¶
OpenConfFromPath unmarshal file which located in disk to memory according to path
func PathIsExist ¶
PathIsExist judge whether path exist. If exist, return true.
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)
SetBytesMode set convert mode: BigEndian or LittleEndian
func SimilarText ¶
Powered by github.com/syyongx/php2go
Types ¶
type BaseEnv ¶
type BaseEnv struct {
// contains filtered or unexported fields
}
func NewBaseEnv ¶
func NewBaseEnv() *BaseEnv
func (*BaseEnv) ReadWithBind ¶
type ByteWalk ¶
type ByteWalk struct {
// contains filtered or unexported fields
}
ByteWalk can extract bytes by bit.
func NewByteWalk ¶
type BytesDecode ¶
type BytesDecode struct {
// contains filtered or unexported fields
}
BytesDecode is used to transform bytes to basic type.
func NewBytesDecode ¶
func NewBytesDecode(_type bool) BytesDecode
func (BytesDecode) BytesToFloat32 ¶
func (decode BytesDecode) BytesToFloat32(buf []byte) float32
BytesToFloat32 return float32 from bytes
func (BytesDecode) BytesToFloat64 ¶
func (decode BytesDecode) BytesToFloat64(buf []byte) float64
BytesToFloat64 return float64 from bytes
func (BytesDecode) BytesToInt16 ¶
func (decode BytesDecode) BytesToInt16(buf []byte) int16
BytesToInt16 return int16 from bytes
func (BytesDecode) BytesToInt32 ¶
func (decode BytesDecode) BytesToInt32(buf []byte) int32
BytesToInt32 return int32 from bytes
func (BytesDecode) BytesToInt64 ¶
func (decode BytesDecode) BytesToInt64(buf []byte) int64
BytesToInt64 return int64 from bytes
type BytesEncode ¶
type BytesEncode struct {
// contains filtered or unexported fields
}
BytesEncode is used to transform basic type to bytes.
func NewBytesEncode ¶
func NewBytesEncode(_type bool) BytesEncode
func (BytesEncode) Float32ToBytes ¶
func (encode BytesEncode) Float32ToBytes(f float32) []byte
Float32ToBytes return bytes from float32
func (BytesEncode) Float64ToBytes ¶
func (encode BytesEncode) Float64ToBytes(f float64) []byte
Float64ToBytes return bytes from float64
func (BytesEncode) Int16ToBytes ¶
func (encode BytesEncode) Int16ToBytes(i int16) []byte
Int16ToBytes return bytes from int16
func (BytesEncode) Int32ToBytes ¶
func (encode BytesEncode) Int32ToBytes(i int32) []byte
Int32ToBytes return bytes from int32
func (BytesEncode) Int64ToBytes ¶
func (encode BytesEncode) Int64ToBytes(i int64) []byte
Int64ToBytes return bytes from int64
type BytesTransfomer ¶
type BytesTransfomer struct { BytesEncode BytesDecode }
BytesTransfomer is used to convert between basic type and bytes
var ByteTransfomer BytesTransfomer
ByteTransfomer is used to transform basic type to bytes, which is BigEndian convert in default. You can use SetBytesMode to switch LittleEndian.
func (BytesTransfomer) AutoToBytes ¶
func (transfomer BytesTransfomer) AutoToBytes(data any) []byte
AutoToBytes return bytes from referred type automatically.
func (BytesTransfomer) AutoToType ¶
func (transfomer BytesTransfomer) AutoToType(raw []byte, _type int) any
AutoToType return any whom type is referred already from bytes.
type CFDictionary ¶
type CFDictionary struct {
// contains filtered or unexported fields
}
func (CFDictionary) GetCFValue ¶
func (c CFDictionary) GetCFValue(field string) CFValue
func (CFDictionary) Set ¶
func (c CFDictionary) Set(field string, v any)
func (CFDictionary) Type ¶
func (CFDictionary) Type() uint8
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 EnvVar ¶
type EnvVar interface { // SetPath set operate target: // windows: sys or user, it's required in windows. // posix: /etc/enviroment, this only is empty method. SetPath(string) error // set global enviroment variable Set(string, any) error // set global enviroment variable when key isn't exist SafeSet(string, any) error // unset (delete) global enviroment variable Unset(string) error // set local enviroment variable SetL(string, string) error // set local enviroment variable when key isn't exist SafeSetL(string, string) error // export current enviroment string into specify file Export(string) error // load enviroment string to be export from disk Load(EnvVarLoadOpt) error // Print current enviroment variable Print() }
EnvVar is an interface to abstract different os enviroment variable
type EnvVarLoadOpt ¶
type EnvVarLoadOpt struct {
// contains filtered or unexported fields
}
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 MetaTable ¶
type MetaTable interface { // SetValue set MetaTable's value and have two different rules: // regedit(windows): MetaValue ✔ MetaMap ✔ MetaArr x (MetaArr not work); // plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔ SetValue(MetaValue) // SafeSetValue set MetaTable's value when key isn't exist and have two different rules: // regedit(windows): MetaValue ✔ MetaMap ✔ MetaArr x (MetaArr not work); // plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔ SafeSetValue(MetaValue) // GetValue return MetaValue according to key GetValue(string) MetaValue // CreateSubTable have two different effect: // regedit(windows): create sub key and written file depond on its feture. // plist(darwin, posix): create sub element of map or array, but not be saved automatically // comparing regedit. It's required to call Write method save manually. CreateSubTable(string) MetaTable // Write to persist MetaValue in disk. // note: The regedit (windows) is written when it is created, // and this method is only valid for plist (darwin, posix). // The regedit is just an empty method. Write() error // Backup save a copy which could restore MetaValue Backup() error // Close to free MetaTable memory Close() }
MetaTable is an interface to abstract plist(darwin) and regedit(windows). In other posix os, uniform use of plist as MetaTable interface implement
func CreateMetaTable ¶
CreateMetaTable to create or open MetaTable
func OpenMetaTable ¶
CreateMetaTable to open MetaTable
type PlistFile ¶
type PlistFile struct {
// contains filtered or unexported fields
}
PlistFile manage plist, which serves for PosixMetaTable
func CreatePlistFile ¶
CreatePlistFile create specify plist when plist isn't exist
func OpenPlistFile ¶
OpenPlistFile open specify plist
func (*PlistFile) GetArr ¶
GetDict returns CFArray. If not exist in plist, it'll return a empty CFArray.
func (*PlistFile) GetArrByField ¶
GetArrByField return CFArray according to field
func (*PlistFile) GetBaseValue ¶
GetBaseValue returns CFValue. If not exist in plist, it'll return CFNone.
func (*PlistFile) GetDict ¶
func (pf *PlistFile) GetDict() CFDictionary
GetDict returns CFDictionary. If not exist in plist, it'll return a empty CFDictionary.
func (*PlistFile) Len ¶
Len return plist length. Length of array or map depend on elements amount. For other type that include string, date, number and so on, it ever returns 1.
func (*PlistFile) SetByField ¶
SetByField set element in sprcify field, which support recurse and meant that you can set a.b.c field.
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) }
PluginFunc is an interface to abstract function to be exported dynamic library
type PosixEnvVar ¶
type PosixEnvVar struct{}
func NewEnvVar ¶
func NewEnvVar() *PosixEnvVar
func (*PosixEnvVar) Export ¶
func (env *PosixEnvVar) Export(file string) error
export current enviroment string into specify file
func (*PosixEnvVar) Load ¶
func (env *PosixEnvVar) Load(opt EnvVarLoadOpt) error
load exported env from disk
func (*PosixEnvVar) SafeSet ¶
func (env *PosixEnvVar) SafeSet(k string, v any) error
set global enviroment variable when key isn't exist
func (*PosixEnvVar) SafeSetL ¶
func (env *PosixEnvVar) SafeSetL(k, v string) error
set local enviroment variable when key isn't exist
func (*PosixEnvVar) Set ¶
func (env *PosixEnvVar) Set(k string, v any) error
set global enviroment variable
func (*PosixEnvVar) SetL ¶
func (env *PosixEnvVar) SetL(k, v string) error
set local enviroment variable
func (*PosixEnvVar) SetPath ¶
func (env *PosixEnvVar) SetPath(path string) error
SetPath set operate target: posix: /etc/enviroment, this only is empty method.
func (*PosixEnvVar) Unset ¶
func (env *PosixEnvVar) Unset(k string) error
unset (delete) global enviroment variable
type PosixMetaTable ¶
type PosixMetaTable struct {
// contains filtered or unexported fields
}
func (*PosixMetaTable) Backup ¶
func (tbl *PosixMetaTable) Backup() error
Backup save a copy which could restore MetaValue
func (*PosixMetaTable) CreateSubTable ¶
func (tbl *PosixMetaTable) CreateSubTable(name string) MetaTable
CreateSubTable create sub element of map or array, but not be saved automatically
func (*PosixMetaTable) GetValue ¶
func (tbl *PosixMetaTable) GetValue(v string) MetaValue
GetValue return MetaValue according to key
func (*PosixMetaTable) SafeSetValue ¶
func (tbl *PosixMetaTable) SafeSetValue(v MetaValue)
SafeSetValue set MetaTable's value when key isn't exist, plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔
func (*PosixMetaTable) SetValue ¶
func (tbl *PosixMetaTable) SetValue(v MetaValue)
SetValue set MetaTable's value, plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔
func (*PosixMetaTable) Write ¶
func (tbl *PosixMetaTable) Write() error
Write to persist MetaValue in disk. note: The regedit (windows) is written when it is created, and this method is only valid for plist (darwin, posix). The regedit is just an empty method.
type PosixPlugin ¶
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 ReflectDict ¶
type ReflectDict struct {
// contains filtered or unexported fields
}
ReflectDict is a type dictionary and manage all type by map.
func NewReflectDict ¶
func NewReflectDict() *ReflectDict
func (*ReflectDict) Load ¶
func (dict *ReflectDict) Load(datas ...any)
Load to register type into ReflectDict
type ReflectObject ¶
type ReflectObject struct {
// contains filtered or unexported fields
}
ReflectObject is an assembly on reflect.Value and relfect.Type.
func NewReflectObject ¶
func NewReflectObject(data any) *ReflectObject
func (*ReflectObject) DumpFields ¶
func (re *ReflectObject) DumpFields()
DumpFields print fields and values for current struct
func (*ReflectObject) Fields ¶
func (re *ReflectObject) Fields() map[string]reflect.Value
Fields return all fields for current type