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

package util

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


Package Files

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


var StatefulServiceType = "StatefulServiceType"

StatefulServiceType 有状态应用

var StatelessServiceType = "StatelessServiceType"

StatelessServiceType 无状态应用

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 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 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 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 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 StringArrayContains Uses

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

StringArrayContains string array contains

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 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 {
    IP   net.IP

IPEVENT ip change event



IPEVENTTYPE ip change event type

const (
    //ADD add event
    //DEL del event
    //UPDATE update event

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.
    // Stderr represents standard error steam type.
    // Systemerr represents errors originating from the system that make it
    // into the the multiplexed stream.

type TimeVersion Uses

type TimeVersion string

TimeVersion time version

func NewTimeVersion Uses

func NewTimeVersion() TimeVersion

NewTimeVersion return version string by time


etcd/etcdlockPackage etcdlock Master election using etcd.

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