tool

package
v0.0.0-...-276be26 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: MIT Imports: 19 Imported by: 8

Documentation

Index

Constants

View Source
const (
	DEFAULT_PORT = 6666
)

Variables

This section is empty.

Functions

func DecodeUriCompontent

func DecodeUriCompontent(encoded string) (string, error)

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 ExternalIP

func ExternalIP() (string, error)

ExternalIP try to find the internet public ip address. it works properly in aliyun network.

TODO only available to get IPv4 address.

ExternalIP 尝试获得LAN地址. 对于aliyun来说,由于eth0是LAN地址,因此此函数能够正确工作; 对于本机多网卡的情况,通常这个函数的结果是正确的;

func FileExists

func FileExists(name string) bool

func FindService

func FindService(what string)

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

func GetCurrentDir

func GetCurrentDir() string

func GetExcutableDir

func GetExcutableDir() string

func IncGrpcListen

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

func IncPort

func IncPort() int

func IncPortAndAddr

func IncPortAndAddr(prefix string) (addr string)

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 JsonToString

func JsonToString(in interface{}, pretty bool) string

func LoadGRPCListen

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

LoadGRPCListen("server.grpc.apply")

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() (ip net.IP, port int, err error)

func LookupHostInfoOld

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

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

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 RandRandSeq

func RandRandSeq() string

func RandSeq

func RandSeq(n int) string

func ThisHost

func ThisHost() (ip net.IP)

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

func ThisHostname

func ThisHostname() string

ThisHostname 返回本机名

func UnescapeUnicode

func UnescapeUnicode(b []byte) string

UnescapeUnicode 解码 \uxxxx 为 unicode 字符; 但是输入的 b 应该是 yaml 格式

func UrlEncodedSimple

func UrlEncodedSimple(str string) (string, error)

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

func YamlToString

func YamlToString(in interface{}, pretty bool) string

Types

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

Jump to

Keyboard shortcuts

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