tool

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_PORT = 6666
)
View Source
const (
	DefaultNilTimeNano = -6795364578871345152 // =DefaultNilTime
)

Variables

This section is empty.

Functions

func BlankIf

func BlankIf(in, defaultValue string) (out string)

func CloneMap

func CloneMap(m map[string]interface{}) map[string]interface{}

func CopySlice

func CopySlice(s interface{}) interface{}

func DecodeUriCompontent

func DecodeUriCompontent(encoded string) (string, error)

func DecodeZigZagInt

func DecodeZigZagInt(b []byte) (r int64, ate int)

DecodeZigZagInt 解码 protobuffer 的变长整数(int8,int16,int32,int64)

func DecodeZigZagUint

func DecodeZigZagUint(b []byte) (r uint64, ate int)

func EncodeUriComponent

func EncodeUriComponent(rawString string) string

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

func FileExists(name string) bool

FileExists returns true if the file `name` was existed.

func FindService

func FindService(what string)

what: "addr", "grpc", "health"

func GetCurrentDir

func GetCurrentDir() string

GetCurrentDir returns the current os working directory pathname.

func GetExcutableDir

func GetExcutableDir() string

GetExcutableDir returns this executable file pathname

func HostToIp

func HostToIp(host string) string

HostToIp would parse string and transform host to ip addresses.

The valid formats are:

host[:port],
scheme://host[:port]/path,

func IncGrpcListen

func IncGrpcListen(prefix string) (listen string, port int)

IncGrpcListen for grpc server

func IncPort

func IncPort() int

func IncPortAndAddr

func IncPortAndAddr(prefix string) (addr string)

func Int64SecondsToTime

func Int64SecondsToTime(utcTimeSeconds int64) (tm time.Time)

func Int64ToTime

func Int64ToTime(utcTime int64) (tm time.Time)

utcTime is a nanoseconds

func Int64ToTimestamp

func Int64ToTimestamp(utcTime int64) (ts *timestamp.Timestamp)

func Intv

func Intv(s string) (v int)

Intv 忽略任何错误转换字符串为整数值并返回。如果无法转换,返回值为0

func IsCancelled

func IsCancelled(err error) (ret bool)

func IsCancelledOrDeadline

func IsCancelledOrDeadline(err error) (ret bool)

func IsDeadline

func IsDeadline(err error) (ret bool)

func IsSlice

func IsSlice(v interface{}) bool

func IsV4

func IsV4(ip net.IP) bool

func IsV6

func IsV6(ip net.IP) bool

func LoadGRPCListenConfig

func LoadGRPCListenConfig(prefix string) (listen string, id string, disabled bool, port int)

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)

LoadGRPCListenConfig loads config info from `prefix`.`serviceName`

func LoadHostDefinition

func LoadHostDefinition(prefix string) (addr string)

LoadHostDefinition loads the dependence info from config entry `server.deps.xxx` LoadHostDefinition("server.deps.apply")

func LookupHostInfo

func LookupHostInfo(ipv6Prefer, ipv4Prefer bool) (ip net.IP, port int, err error)

func LookupHostInfoOld

func LookupHostInfoOld() (net.IP, int, error)

LookupHostInfoOld 依据配置文件的 server.rpc_address 尝试解释正确的rpc地址,通常是IPv4的

func LookupHostInfoOld2

func LookupHostInfoOld2() (ip net.IP, port int, err error)

func MergeMap

func MergeMap(maps ...map[string]interface{}) map[string]interface{}

func MergeSlice

func MergeSlice(target interface{}, source interface{}) interface{}

func NullIf

func NullIf(in, defaultValue interface{}) (out interface{})

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{}

func Port

func Port() int

func PressAnyKeyToContinue

func PressAnyKeyToContinue(msg ...string) (input string)

func PressEnterToContinue

func PressEnterToContinue(msg ...string) (input string)

func RandRandSeq

func RandRandSeq() string

RandRandSeq returns a random string with random length (1..127)

func RandSeq

func RandSeq(n int) string

RandSeq returns a random string with specified length 'n'

func RandSeqln

func RandSeqln(n int) string

RandSeqln returns a random string with specified length 'n', and it has a '\n' character tail.

func String

func String(length int) string

String returns a random string with length specified

func StringVariantLength

func StringVariantLength(minLength, maxLength int) string

String returns a random string with length specified

func StringWithCharset

func StringWithCharset(length int, charset string) string

StringWithCharset generate random string

func ThisHost

func ThisHost() (ip net.IP)

ThisHost 返回当前服务器的LAN ip,通过本机名进行反向解析

func ThisHostname

func ThisHostname() string

ThisHostname 返回本机名

func TimeToTimestamp

func TimeToTimestamp(tm time.Time) (ts *timestamp.Timestamp)

func TimestampToTime

func TimestampToTime(ts *timestamp.Timestamp) (tm time.Time)

func UrlEncodedSimple

func UrlEncodedSimple(str string) (string, error)

UrlEncoded encodes a string like Javascript's encodeURIComponent() Example: Turns "My String" to "My%20String"

func ZeroIf

func ZeroIf(in, defaultValue uint64) (out uint64)

func ZeroIfAny

func ZeroIfAny(in, defaultValue interface{}) (out interface{})

Types

type Copier

type Copier interface {
	SetIgnoreNames(ignoreNames ...string) Copier
	Copy(maps ...map[string]interface{}) (result map[string]interface{}, err error)
}

type DiskStatus

type DiskStatus struct {
	All  uint64 `json:"all"`
	Used uint64 `json:"used"`
	Free uint64 `json:"free"`
}

func DiskUsage

func DiskUsage(path string) (disk *DiskStatus)

disk usage of path/disk

type EscapeError

type EscapeError string

func (EscapeError) Error

func (e EscapeError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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