rainbond: github.com/goodrain/rainbond/util Index | Files | Directories

package util

import "github.com/goodrain/rainbond/util"

Index

Package Files

bytes.go chan.go comman.go command.go constants.go convert_types.go copyio.go hash.go ip.go ippool.go language.go pprofer.go sshclient.go string.go uuid.go

Variables

var StatefulServiceType = "StatefulServiceType"

StatefulServiceType 有状态应用

var StatelessServiceType = "StatelessServiceType"

StatelessServiceType 无状态应用

func Bool Uses

func Bool(v bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolMap Uses

func BoolMap(src map[string]bool) map[string]*bool

BoolMap converts a string map of bool values into a string map of bool pointers

func BoolSlice Uses

func BoolSlice(src []bool) []*bool

BoolSlice converts a slice of bool values into a slice of bool pointers

func BoolValue Uses

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func BoolValueMap Uses

func BoolValueMap(src map[string]*bool) map[string]bool

BoolValueMap converts a string map of bool pointers into a string map of bool values

func BoolValueSlice Uses

func BoolValueSlice(src []*bool) []bool

BoolValueSlice converts a slice of bool pointers into a slice of bool values

func BytesSliceEqual Uses

func BytesSliceEqual(a, b []byte) bool

BytesSliceEqual BytesSliceEqual

func CheckAndCreateDir Uses

func CheckAndCreateDir(path string) error

CheckAndCreateDir check and create dir

func CheckAndCreateDirByMode Uses

func CheckAndCreateDirByMode(path string, mode os.FileMode) error

CheckAndCreateDirByMode check and create dir

func CheckIP Uses

func CheckIP(ip string) bool

CheckIP Verify IP address validity

func CmdExec Uses

func CmdExec(args string) (string, error)

CmdExec CmdExec

func CmdRunWithTimeout Uses

func CmdRunWithTimeout(cmd *exec.Cmd, timeout time.Duration) (bool, error)

CmdRunWithTimeout exec cmd with timeout

func CopyFile Uses

func CopyFile(source, target string) error

CopyFile copy source file to target direct io read and write file Keep the permissions user and group

func CreateFileHash Uses

func CreateFileHash(sourceFile, hashfile string) error

CreateFileHash compute sourcefile hash and write hashfile

func CreateHashString Uses

func CreateHashString(source string) (hashstr string, err error)

CreateHashString create hash string

func CreateHostID Uses

func CreateHostID() (string, error)

CreateHostID create host id by mac addr

func CreateVersionByTime Uses

func CreateVersionByTime() string

CreateVersionByTime create version number

func Deweight Uses

func Deweight(data *[]string)

Deweight 去除数组重复

func DirIsEmpty Uses

func DirIsEmpty(dir string) bool

DirIsEmpty 验证目录是否为空

func Exec Uses

func Exec(ctx context.Context, f func() error, wait time.Duration) error

Exec 上下文执行

func FileExists Uses

func FileExists(filename string) (bool, error)

FileExists check file exist

func FileExistsWithSuffix Uses

func FileExistsWithSuffix(pathDir, suffix string) bool

FileExistsWithSuffix 指定目录是否含有指定后缀的文件

func Float32 Uses

func Float32(v float32) *float32

Float32 returns a pointer to the float32 value passed in.

func Float32Map Uses

func Float32Map(src map[string]float32) map[string]*float32

Float32Map converts a string map of float32 values into a string map of float32 pointers

func Float32Slice Uses

func Float32Slice(src []float32) []*float32

Float32Slice converts a slice of float32 values into a slice of float32 pointers

func Float32Value Uses

func Float32Value(v *float32) float32

Float32Value returns the value of the float32 pointer passed in or 0 if the pointer is nil.

func Float32ValueMap Uses

func Float32ValueMap(src map[string]*float32) map[string]float32

Float32ValueMap converts a string map of float32 pointers into a string map of float32 values

func Float32ValueSlice Uses

func Float32ValueSlice(src []*float32) []float32

Float32ValueSlice converts a slice of float32 pointers into a slice of float32 values

func Float64 Uses

func Float64(v float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Map Uses

func Float64Map(src map[string]float64) map[string]*float64

Float64Map converts a string map of float64 values into a string map of float64 pointers

func Float64Slice Uses

func Float64Slice(src []float64) []*float64

Float64Slice converts a slice of float64 values into a slice of float64 pointers

func Float64Value Uses

func Float64Value(v *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Float64ValueMap Uses

func Float64ValueMap(src map[string]*float64) map[string]float64

Float64ValueMap converts a string map of float64 pointers into a string map of float64 values

func Float64ValueSlice Uses

func Float64ValueSlice(src []*float64) []float64

Float64ValueSlice converts a slice of float64 pointers into a slice of float64 values

func GetCurrentDir Uses

func GetCurrentDir() string

GetCurrentDir get current dir

func GetDirList Uses

func GetDirList(dirpath string, level int) ([]string, error)

GetDirList get all lower level dir

func GetDirNameList Uses

func GetDirNameList(dirpath string, level int) ([]string, error)

GetDirNameList get all lower level dir

func GetDirSize Uses

func GetDirSize(path string) float64

GetDirSize kb为单位

func GetDirSizeByCmd Uses

func GetDirSizeByCmd(path string) float64

GetDirSizeByCmd get dir sizes by du command return kb

func GetFileList Uses

func GetFileList(dirpath string, level int) ([]string, error)

GetFileList -

func GetFileSize Uses

func GetFileSize(path string) int64

GetFileSize get file size

func GetIDFromKey Uses

func GetIDFromKey(key string) string

GetIDFromKey 从 etcd 的 key 中取 id

func GetParentDirectory Uses

func GetParentDirectory(dirctory string) string

GetParentDirectory GetParentDirectory

func Int Uses

func Int(v int) *int

Int returns a pointer to the int value passed in.

func Int16 Uses

func Int16(v int16) *int16

Int16 returns a pointer to the int16 value passed in.

func Int16Map Uses

func Int16Map(src map[string]int16) map[string]*int16

Int16Map converts a string map of int16 values into a string map of int16 pointers

func Int16Slice Uses

func Int16Slice(src []int16) []*int16

Int16Slice converts a slice of int16 values into a slice of int16 pointers

func Int16Value Uses

func Int16Value(v *int16) int16

Int16Value returns the value of the int16 pointer passed in or 0 if the pointer is nil.

func Int16ValueMap Uses

func Int16ValueMap(src map[string]*int16) map[string]int16

Int16ValueMap converts a string map of int16 pointers into a string map of int16 values

func Int16ValueSlice Uses

func Int16ValueSlice(src []*int16) []int16

Int16ValueSlice converts a slice of int16 pointers into a slice of int16 values

func Int32 Uses

func Int32(v int32) *int32

Int32 returns a pointer to the int32 value passed in.

func Int32Map Uses

func Int32Map(src map[string]int32) map[string]*int32

Int32Map converts a string map of int32 values into a string map of int32 pointers

func Int32Slice Uses

func Int32Slice(src []int32) []*int32

Int32Slice converts a slice of int32 values into a slice of int32 pointers

func Int32Value Uses

func Int32Value(v *int32) int32

Int32Value returns the value of the int32 pointer passed in or 0 if the pointer is nil.

func Int32ValueMap Uses

func Int32ValueMap(src map[string]*int32) map[string]int32

Int32ValueMap converts a string map of int32 pointers into a string map of int32 values

func Int32ValueSlice Uses

func Int32ValueSlice(src []*int32) []int32

Int32ValueSlice converts a slice of int32 pointers into a slice of int32 values

func Int64 Uses

func Int64(v int64) *int64

Int64 returns a pointer to the int64 value passed in.

func Int64Map Uses

func Int64Map(src map[string]int64) map[string]*int64

Int64Map converts a string map of int64 values into a string map of int64 pointers

func Int64Slice Uses

func Int64Slice(src []int64) []*int64

Int64Slice converts a slice of int64 values into a slice of int64 pointers

func Int64Value Uses

func Int64Value(v *int64) int64

Int64Value returns the value of the int64 pointer passed in or 0 if the pointer is nil.

func Int64ValueMap Uses

func Int64ValueMap(src map[string]*int64) map[string]int64

Int64ValueMap converts a string map of int64 pointers into a string map of int64 values

func Int64ValueSlice Uses

func Int64ValueSlice(src []*int64) []int64

Int64ValueSlice converts a slice of int64 pointers into a slice of int64 values

func Int8 Uses

func Int8(v int8) *int8

Int8 returns a pointer to the int8 value passed in.

func Int8Map Uses

func Int8Map(src map[string]int8) map[string]*int8

Int8Map converts a string map of int8 values into a string map of int8 pointers

func Int8Slice Uses

func Int8Slice(src []int8) []*int8

Int8Slice converts a slice of int8 values into a slice of int8 pointers

func Int8Value Uses

func Int8Value(v *int8) int8

Int8Value returns the value of the int8 pointer passed in or 0 if the pointer is nil.

func Int8ValueMap Uses

func Int8ValueMap(src map[string]*int8) map[string]int8

Int8ValueMap converts a string map of int8 pointers into a string map of int8 values

func Int8ValueSlice Uses

func Int8ValueSlice(src []*int8) []int8

Int8ValueSlice converts a slice of int8 pointers into a slice of int8 values

func IntMap Uses

func IntMap(src map[string]int) map[string]*int

IntMap converts a string map of int values into a string map of int pointers

func IntSlice Uses

func IntSlice(src []int) []*int

IntSlice converts a slice of int values into a slice of int pointers

func IntValue Uses

func IntValue(v *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func IntValueMap Uses

func IntValueMap(src map[string]*int) map[string]int

IntValueMap converts a string map of int pointers into a string map of int values

func IntValueSlice Uses

func IntValueSlice(src []*int) []int

IntValueSlice converts a slice of int pointers into a slice of int values

func IntermittentExec Uses

func IntermittentExec(ctx context.Context, f func(), t time.Duration)

IntermittentExec 间歇性执行

func IsDir Uses

func IsDir(path string) (bool, error)

IsDir path is dir

func IsHaveFile Uses

func IsHaveFile(path string) bool

IsHaveFile 指定目录是否含有文件 .开头文件除外

func LocalIP Uses

func LocalIP() (net.IP, error)

LocalIP 获取本机 ip 获取第一个非 loopback ip

func MergeDir Uses

func MergeDir(fromdir, todir string) error

MergeDir MergeDir if Subdirectories already exist, Don't replace

func MillisecondsTimeValue Uses

func MillisecondsTimeValue(v *int64) time.Time

MillisecondsTimeValue converts an int64 pointer to a time.Time value representing milliseconds sinch Epoch or time.Time{} if the pointer is nil.

func NewUUID Uses

func NewUUID() string

NewUUID 创建无-的32位uuid

func OpenOrCreateFile Uses

func OpenOrCreateFile(filename string) (*os.File, error)

OpenOrCreateFile open or create file

func ParseVariable Uses

func ParseVariable(source string, configs map[string]string) string

ParseVariable parse and replace variable in source str

func ProfilerSetup Uses

func ProfilerSetup(r ServeMux)

ProfilerSetup pprof route

func ReadHostID Uses

func ReadHostID(filePath string) (string, error)

ReadHostID 读取当前机器ID ID是节点的唯一标识,acp_node将把ID与机器信息的绑定关系维护于etcd中

func RemoveSpaces Uses

func RemoveSpaces(sources []string) (re []string)

RemoveSpaces 去除空格项

func Rename Uses

func Rename(old, new string) error

Rename move file

func SearchFile Uses

func SearchFile(pathDir, name string, level int) bool

SearchFile 搜索指定目录是否有指定文件,指定搜索目录层数,-1为全目录搜索

func SearchFileBody Uses

func SearchFileBody(filename, searchStr string) bool

SearchFileBody 搜索文件中是否含有指定字符串

func SecondsTimeValue Uses

func SecondsTimeValue(v *int64) time.Time

SecondsTimeValue converts an int64 pointer to a time.Time value representing seconds since Epoch or time.Time{} if the pointer is nil.

func SendNoBlocking Uses

func SendNoBlocking(m []byte, ch chan []byte)

SendNoBlocking 无阻塞发送

func StdCopy Uses

func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error)

StdCopy is a modified version of io.Copy.

StdCopy will demultiplex `src`, assuming that it contains two streams, previously multiplexed together using a StdWriter instance. As it reads from `src`, StdCopy will write to `dstout` and `dsterr`.

StdCopy will read until it hits EOF on `src`. It will then return a nil error. In other words: if `err` is non nil, it indicates a real underlying error.

`written` will hold the total number of bytes written to `dstout` and `dsterr`.

func String Uses

func String(v string) *string

String returns a pointer to the string value passed in.

func StringArrayContains Uses

func StringArrayContains(list []string, source string) bool

StringArrayContains string array contains

func StringMap Uses

func StringMap(src map[string]string) map[string]*string

StringMap converts a string map of string values into a string map of string pointers

func StringSlice Uses

func StringSlice(src []string) []*string

StringSlice converts a slice of string values into a slice of string pointers

func StringValue Uses

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func StringValueMap Uses

func StringValueMap(src map[string]*string) map[string]string

StringValueMap converts a string map of string pointers into a string map of string values

func StringValueSlice Uses

func StringValueSlice(src []*string) []string

StringValueSlice converts a slice of string pointers into a slice of string values

func Time Uses

func Time(v time.Time) *time.Time

Time returns a pointer to the time.Time value passed in.

func TimeMap Uses

func TimeMap(src map[string]time.Time) map[string]*time.Time

TimeMap converts a string map of time.Time values into a string map of time.Time pointers

func TimeSlice Uses

func TimeSlice(src []time.Time) []*time.Time

TimeSlice converts a slice of time.Time values into a slice of time.Time pointers

func TimeUnixMilli Uses

func TimeUnixMilli(t time.Time) int64

TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC". The result is undefined if the Unix time cannot be represented by an int64. Which includes calling TimeUnixMilli on a zero Time is undefined.

This utility is useful for service API's such as CloudWatch Logs which require their unix time values to be in milliseconds.

See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information.

func TimeValue Uses

func TimeValue(v *time.Time) time.Time

TimeValue returns the value of the time.Time pointer passed in or time.Time{} if the pointer is nil.

func TimeValueMap Uses

func TimeValueMap(src map[string]*time.Time) map[string]time.Time

TimeValueMap converts a string map of time.Time pointers into a string map of time.Time values

func TimeValueSlice Uses

func TimeValueSlice(src []*time.Time) []time.Time

TimeValueSlice converts a slice of time.Time pointers into a slice of time.Time values

func ToByte Uses

func ToByte(v string) []byte

ToByte string to []byte BenchmarkToByte-4 2000000000 0.36 ns/op

func ToString Uses

func ToString(b []byte) string

ToString []byte to string BenchmarkToString-4 30000000 42.0 ns/op

func Translation Uses

func Translation(english string) string

Translation Translation English to Chinese

func Uint Uses

func Uint(v uint) *uint

Uint returns a pointer to the uint value passed in.

func Uint16 Uses

func Uint16(v uint16) *uint16

Uint16 returns a pointer to the uint16 value passed in.

func Uint16Map Uses

func Uint16Map(src map[string]uint16) map[string]*uint16

Uint16Map converts a string map of uint16 values into a string map of uint16 pointers

func Uint16Slice Uses

func Uint16Slice(src []uint16) []*uint16

Uint16Slice converts a slice of uint16 values into a slice of uint16 pointers

func Uint16Value Uses

func Uint16Value(v *uint16) uint16

Uint16Value returns the value of the uint16 pointer passed in or 0 if the pointer is nil.

func Uint16ValueMap Uses

func Uint16ValueMap(src map[string]*uint16) map[string]uint16

Uint16ValueMap converts a string map of uint16 pointers into a string map of uint16 values

func Uint16ValueSlice Uses

func Uint16ValueSlice(src []*uint16) []uint16

Uint16ValueSlice converts a slice of uint16 pointers into a slice of uint16 values

func Uint32 Uses

func Uint32(v uint32) *uint32

Uint32 returns a pointer to the uint32 value passed in.

func Uint32Map Uses

func Uint32Map(src map[string]uint32) map[string]*uint32

Uint32Map converts a string map of uint32 values into a string map of uint32 pointers

func Uint32Slice Uses

func Uint32Slice(src []uint32) []*uint32

Uint32Slice converts a slice of uint32 values into a slice of uint32 pointers

func Uint32Value Uses

func Uint32Value(v *uint32) uint32

Uint32Value returns the value of the uint32 pointer passed in or 0 if the pointer is nil.

func Uint32ValueMap Uses

func Uint32ValueMap(src map[string]*uint32) map[string]uint32

Uint32ValueMap converts a string map of uint32 pointers into a string map of uint32 values

func Uint32ValueSlice Uses

func Uint32ValueSlice(src []*uint32) []uint32

Uint32ValueSlice converts a slice of uint32 pointers into a slice of uint32 values

func Uint64 Uses

func Uint64(v uint64) *uint64

Uint64 returns a pointer to the uint64 value passed in.

func Uint64Map Uses

func Uint64Map(src map[string]uint64) map[string]*uint64

Uint64Map converts a string map of uint64 values into a string map of uint64 pointers

func Uint64Slice Uses

func Uint64Slice(src []uint64) []*uint64

Uint64Slice converts a slice of uint64 values into a slice of uint64 pointers

func Uint64Value Uses

func Uint64Value(v *uint64) uint64

Uint64Value returns the value of the uint64 pointer passed in or 0 if the pointer is nil.

func Uint64ValueMap Uses

func Uint64ValueMap(src map[string]*uint64) map[string]uint64

Uint64ValueMap converts a string map of uint64 pointers into a string map of uint64 values

func Uint64ValueSlice Uses

func Uint64ValueSlice(src []*uint64) []uint64

Uint64ValueSlice converts a slice of uint64 pointers into a slice of uint64 values

func Uint8 Uses

func Uint8(v uint8) *uint8

Uint8 returns a pointer to the uint8 value passed in.

func Uint8Map Uses

func Uint8Map(src map[string]uint8) map[string]*uint8

Uint8Map converts a string map of uint8 values into a string map of uint8 pointers

func Uint8Slice Uses

func Uint8Slice(src []uint8) []*uint8

Uint8Slice converts a slice of uint8 values into a slice of uint8 pointers

func Uint8Value Uses

func Uint8Value(v *uint8) uint8

Uint8Value returns the value of the uint8 pointer passed in or 0 if the pointer is nil.

func Uint8ValueMap Uses

func Uint8ValueMap(src map[string]*uint8) map[string]uint8

Uint8ValueMap converts a string map of uint8 pointers into a string map of uint8 values

func Uint8ValueSlice Uses

func Uint8ValueSlice(src []*uint8) []uint8

Uint8ValueSlice converts a slice of uint8 pointers into a slice of uint8 values

func UintMap Uses

func UintMap(src map[string]uint) map[string]*uint

UintMap converts a string map of uint values uinto a string map of uint pointers

func UintSlice Uses

func UintSlice(src []uint) []*uint

UintSlice converts a slice of uint values uinto a slice of uint pointers

func UintValue Uses

func UintValue(v *uint) uint

UintValue returns the value of the uint pointer passed in or 0 if the pointer is nil.

func UintValueMap Uses

func UintValueMap(src map[string]*uint) map[string]uint

UintValueMap converts a string map of uint pointers uinto a string map of uint values

func UintValueSlice Uses

func UintValueSlice(src []*uint) []uint

UintValueSlice converts a slice of uint pointers uinto a slice of uint values

func Unzip Uses

func Unzip(archive, target string) error

Unzip archive file to target dir

func Zip Uses

func Zip(source, target string) error

Zip zip compressing source dir to target file

type IPEVENT Uses

type IPEVENT struct {
    Type IPEVENTTYPE
    IP   net.IP
}

IPEVENT ip change event

type IPEVENTTYPE Uses

type IPEVENTTYPE int

IPEVENTTYPE ip change event type

const (
    //ADD add event
    ADD IPEVENTTYPE = iota
    //DEL del event
    DEL
    //UPDATE update event
    UPDATE
)

type IPPool Uses

type IPPool struct {
    HostIPs map[string]net.IP
    EventCh chan IPEVENT
    StopCh  chan struct{}
    // contains filtered or unexported fields
}

IPPool ip pool

func NewIPPool Uses

func NewIPPool(ignoreInterfaceName []string) *IPPool

NewIPPool new ip pool

func (*IPPool) Close Uses

func (i *IPPool) Close()

Close close

func (*IPPool) GetHostIPs Uses

func (i *IPPool) GetHostIPs() []net.IP

GetHostIPs get host ips

func (*IPPool) GetWatchIPChan Uses

func (i *IPPool) GetWatchIPChan() <-chan IPEVENT

GetWatchIPChan watch ip change

func (*IPPool) LoopCheckIPs Uses

func (i *IPPool) LoopCheckIPs()

LoopCheckIPs loop check ips

func (*IPPool) Ready Uses

func (i *IPPool) Ready() bool

Ready ready

type PipeCommand Uses

type PipeCommand struct {
    // contains filtered or unexported fields
}

PipeCommand PipeCommand

func NewPipeCommand Uses

func NewPipeCommand(stack ...*exec.Cmd) (*PipeCommand, error)

NewPipeCommand new pipe commands

func (*PipeCommand) GetFinalStderr Uses

func (p *PipeCommand) GetFinalStderr() io.Reader

GetFinalStderr get final command stderr reader

func (*PipeCommand) GetFinalStdout Uses

func (p *PipeCommand) GetFinalStdout() io.Reader

GetFinalStdout get final command stdout reader

func (*PipeCommand) Run Uses

func (p *PipeCommand) Run() error

Run Run

type SSHClient Uses

type SSHClient struct {
    IP             string
    Port           int
    User           string
    Password       string
    Method         string
    Key            string
    Stdout, Stderr io.Writer
    Cmd            string
}

SSHClient ssh client

func NewSSHClient Uses

func NewSSHClient(ip, user, password, cmd string, port int, stdout, stderr io.Writer) *SSHClient

NewSSHClient new ssh client

func (*SSHClient) Connection Uses

func (server *SSHClient) Connection() error

Connection 执行远程连接

type ServeMux Uses

type ServeMux interface {
    HandleFunc(pattern string, funC http.HandlerFunc)
}

ServeMux -

type StdType Uses

type StdType byte

StdType is the type of standard stream a writer can multiplex to.

const (
    // Stdin represents standard input stream type.
    Stdin StdType = iota
    // Stdout represents standard output stream type.
    Stdout
    // Stderr represents standard error steam type.
    Stderr
    // Systemerr represents errors originating from the system that make it
    // into the the multiplexed stream.
    Systemerr
)

type TimeVersion Uses

type TimeVersion string

TimeVersion time version

func NewTimeVersion Uses

func NewTimeVersion() TimeVersion

NewTimeVersion return version string by time

Directories

PathSynopsis
ansible
cert
disk
endpoint
etcd
etcd/etcdlockPackage etcdlock Master election using etcd.
http
k8s
leader
license
log
prober
prober/probes
prober/types/v1
sync
watch
windows
zip

Package util imports 31 packages (graph) and is imported by 50 packages. Updated 2019-11-15. Refresh now. Tools for package owners.