Documentation
¶
Index ¶
- Constants
- Variables
- func BlankIf(in, defaultValue string) (out string)
- func Clone(fromValue, toValue interface{}) interface{}
- func CloneMap(m map[string]interface{}) map[string]interface{}
- func CopySlice(s interface{}) interface{}
- func DecodeURIComponent(encoded string) (string, error)
- func DecodeZigZagInt(b []byte) (r int64, ate int)
- func DecodeZigZagUint(b []byte) (r uint64, ate int)
- func EncodeURIComponent(rawString string) string
- func FileExists(name string) bool
- func FindService(what string)
- func GetCurrentDir() string
- func GetExecutableDir() string
- func HostToIP(host string) string
- func IncGRPCListen(prefix string) (listen string, port int)
- func IncPort() int
- func IncPortAndAddr(prefix string) (addr string)
- func Int64SecondsToTime(utcTimeSeconds int64) (tm time.Time)
- func Int64ToTime(utcTime int64) (tm time.Time)
- func Int64ToTimestamp(utcTime int64) (ts *timestamp.Timestamp)
- func Intv(s string) (v int)
- func IsCancelled(err error) (ret bool)
- func IsCancelledOrDeadline(err error) (ret bool)
- func IsDeadline(err error) (ret bool)
- func IsSlice(v interface{}) bool
- func IsV4(ip net.IP) bool
- func IsV6(ip net.IP) bool
- func LoadGRPCListenConfig(prefix string) (listen string, id string, disabled bool, port int)
- func LoadGRPCListenSpecialConfig(prefix, serviceName string) (listen string, id string, disabled bool, port int)
- func LoadHostDefinition(prefix string) (addr string)
- func LookupHostInfo(ipv6Prefer, ipv4Prefer bool) (ip net.IP, port int, err error)
- func LookupHostInfoOld() (net.IP, int, error)
- func Md5Sign(willSignStr string, secret string) string
- func MergeMap(maps ...map[string]interface{}) map[string]interface{}
- func MergeSlice(target interface{}, source interface{}) interface{}
- func MyKeyRuleValidate(cliKey string) bool
- func NullIf(in, defaultValue interface{}) (out interface{})
- func Pollard(in interface{}) interface{}
- func PollardArray(in []interface{}) interface{}
- func Port() int
- func PressAnyKeyToContinue(msg ...string) (input string)
- func PressEnterToContinue(msg ...string) (input string)
- func RandRandSeq() string
- func RandSeq(n int) string
- func RandSeqln(n int) string
- func String(length int) string
- func StringVariantLength(minLength, maxLength int) string
- func StringWithCharset(length int, charset string) string
- func ThisHost() (ip net.IP)
- func ThisHostname() string
- func TimeToTimestamp(tm time.Time) (ts *timestamp.Timestamp)
- func TimestampToTime(ts *timestamp.Timestamp) (tm time.Time)
- func URLEncodedSimple(str string) (string, error)
- func UUid() string
- func ZeroIf(in, defaultValue uint64) (out uint64)
- func ZeroIfAny(in, defaultValue interface{}) (out interface{})
- type Copier
- type DiskStatus
- type EscapeError
- type MapCopier
Constants ¶
const ( // DefaultNilTimeNano is a large number to nil proto Time DefaultNilTimeNano = -6795364578871345152 // =DefaultNilTime )
const (
// DefaultPort is unused
DefaultPort = 6666
)
Variables ¶
var ( // GormDefaultCopier used for gorm GormDefaultCopier = &copierImpl{KeepIfFromIsNil: true, ZeroIfEqualsFrom: true, KeepIfFromIsZero: true, EachFieldAlways: true} // StandardCopier is a normal copier StandardCopier = &copierImpl{} )
Functions ¶
func Clone ¶
func Clone(fromValue, toValue interface{}) interface{}
Clone deep copy source to target
func CopySlice ¶
func CopySlice(s interface{}) interface{}
CopySlice do a generic copy from slice to new slice.
func DecodeURIComponent ¶
DecodeURIComponent reverts the working by EncodeURIComponent
func DecodeZigZagInt ¶
DecodeZigZagInt decodes the protobuffer ZigZag number(int8,int16,int32,int64)
func DecodeZigZagUint ¶
DecodeZigZagUint decodes the protobuffer ZigZag number(int8,int16,int32,int64)
func EncodeURIComponent ¶
EncodeURIComponent convert 'a b/c' -> 'a+b%2fc' origin := "äöüHel/lo world" encoded := EncodeURIComponent(origin) fmt.Println(encoded)
s, _ := DecodeUriCompontent(encoded) fmt.Println(s)
func FileExists ¶
FileExists returns true if the file `name` was existed.
func FindService ¶
func FindService(what string)
FindService not implements
what: "addr", "grpc", "health"
func GetCurrentDir ¶
func GetCurrentDir() string
GetCurrentDir returns the current os working directory pathname.
func GetExecutableDir ¶
func GetExecutableDir() string
GetExecutableDir returns this executable file pathname
func HostToIP ¶
HostToIP would parse string and transform host to ip addresses.
The valid formats are:
host[:port], scheme://host[:port]/path,
func IncGRPCListen ¶
IncGRPCListen for grpc server
func IncPortAndAddr ¶
IncPortAndAddr adds 1 to the port, and return the formatted address like "10.0.0.7:8080"
func Int64SecondsToTime ¶
Int64SecondsToTime converts the seconds 'utcTimeSeconds' to golang Time
func Int64ToTime ¶
Int64ToTime converts the nanoseconds 'utcTime' to golang Time
func Int64ToTimestamp ¶
Int64ToTimestamp converts the nanoseconds 'utcTime' to protobuffer timestamp
func IsCancelled ¶
IsCancelled tests 'err' if it is `context.Canceled`.
func IsCancelledOrDeadline ¶
IsCancelledOrDeadline tests 'err' if it is `context.Canceled` or `context.DeadlineExceeded`.
func IsDeadline ¶
IsDeadline tests 'err' if it is `context.DeadlineExceeded`.
func LoadGRPCListenConfig ¶
LoadGRPCListenConfig loads config info of MAIN grpc service Generally, it loads a map from `prefix` (such as "server.grpc.<service-name>") and extract sub-keys: "listen", "id", "disabled"
func LoadGRPCListenSpecialConfig ¶
func LoadGRPCListenSpecialConfig(prefix, serviceName string) (listen string, id string, disabled bool, port int)
LoadGRPCListenSpecialConfig loads config info from `prefix`.`serviceName`
func LoadHostDefinition ¶
LoadHostDefinition loads the dependence info from config entry `server.deps.xxx`. LoadHostDefinition("server.deps.apply")
func LookupHostInfo ¶
LookupHostInfo scans the network adapters on local machine, finds all available IPs
func LookupHostInfoOld ¶
LookupHostInfoOld 依据配置文件的 server.rpc_address 尝试解释正确的rpc地址,通常是IPv4的
func MergeSlice ¶
func MergeSlice(target interface{}, source interface{}) interface{}
MergeSlice do a merging on generic slice type.
func MyKeyRuleValidate ¶
func NullIf ¶
func NullIf(in, defaultValue interface{}) (out interface{})
NullIf return 'in' if it is not nil, or return the defaultValue if 'in' is nil.
func Pollard ¶
func Pollard(in interface{}) interface{}
Pollard 转换一个泛型对象中的全部 map[interface{}]interface{} 子对象为 map[string]interface{} 在转换完毕之后,新的返回对象将能够正确地被json编码: text = `age: 12 name: joe` obj, err := yaml.Unmarshal(text) b, err := json.Marshal(Pollard(obj))
典型的用途在于将 golang 对象直接json输出时
func PollardArray ¶
func PollardArray(in []interface{}) interface{}
PollardArray converts 'in' to new return object A.
func PressAnyKeyToContinue ¶
PressAnyKeyToContinue prompts and waiting user's keystroke in terminal
func PressEnterToContinue ¶
PressEnterToContinue prompts and waiting user's keystroke in terminal
func RandRandSeq ¶
func RandRandSeq() string
RandRandSeq returns a random string with random length (1..127)
func RandSeqln ¶
RandSeqln returns a random string with specified length 'n', and it has a '\n' character tail.
func StringVariantLength ¶
StringVariantLength returns a random string with length specified
func StringWithCharset ¶
StringWithCharset generate random string
func TimeToTimestamp ¶
TimeToTimestamp converts the golang Time value to protobuffer timestamp
func TimestampToTime ¶
TimestampToTime converts the protobuffer timestamp to golang Time
func URLEncodedSimple ¶
URLEncodedSimple encodes a string like Javascript's encodeURIComponent() Example: Turns "My String" to "My%20String"
Types ¶
type Copier ¶
type Copier interface { SetIgnoreNames(ignoreNames ...string) Copier SetEachFieldAlways(b bool) Copier Copy(toValue interface{}, fromValue interface{}, ignoreNames ...string) (err error) }
Copier interface Copier is based on from github.com/jinzhu/copier
type DiskStatus ¶
type DiskStatus struct { All uint64 `json:"all"` Used uint64 `json:"used"` Free uint64 `json:"free"` }
DiskStatus provides the disk usages
func DiskUsage ¶
func DiskUsage(path string) (disk *DiskStatus)
DiskUsage is for disk usage of path/disk
type EscapeError ¶
type EscapeError string
EscapeError is an error type
func (EscapeError) Error ¶
func (e EscapeError) Error() string