util

package
v3.6.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: LGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StatefulServiceType = "StatefulServiceType"

StatefulServiceType 有状态应用

View Source
var StatelessServiceType = "StatelessServiceType"

StatelessServiceType 无状态应用

Functions

func CheckAndCreateDir

func CheckAndCreateDir(path string) error

CheckAndCreateDir check and create dir

func CmdExec

func CmdExec(args string) (string, error)

CmdExec CmdExec

func CmdRunWithTimeout

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

CmdRunWithTimeout exec cmd with timeout

func CreateFileHash

func CreateFileHash(sourceFile, hashfile string) error

CreateFileHash compute sourcefile hash and write hashfile

func CreateVersionByTime

func CreateVersionByTime() string

CreateVersionByTime create version number

func Deweight

func Deweight(data *[]string)

Deweight 去除数组重复

func DirIsEmpty

func DirIsEmpty(dir string) bool

DirIsEmpty 验证目录是否为空

func Exec

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

Exec 上下文执行

func FileExists

func FileExists(filename string) (bool, error)

FileExists check file exist

func FileExistsWithSuffix

func FileExistsWithSuffix(pathDir, suffix string) bool

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

func GetDirList

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

GetDirList get all lower level dir

func GetDirNameList

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

GetDirNameList get all lower level dir

func GetDirSize

func GetDirSize(path string) float64

GetDirSize kb为单位

func GetDirSizeByCmd

func GetDirSizeByCmd(path string) float64

GetDirSizeByCmd get dir sizes by du command return kb

func GetFileList

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

func GetFileSize

func GetFileSize(path string) int64

GetFileSize get file size

func GetIDFromKey

func GetIDFromKey(key string) string

GetIDFromKey 从 etcd 的 key 中取 id

func GetParentDirectory

func GetParentDirectory(dirctory string) string

GetParentDirectory GetParentDirectory

func IntermittentExec

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

IntermittentExec 间歇性执行

func IsHaveFile

func IsHaveFile(path string) bool

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

func LocalIP

func LocalIP() (net.IP, error)

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

func NewUUID

func NewUUID() string

NewUUID 创建无-的32位uuid

func OpenOrCreateFile

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

OpenOrCreateFile open or create file

func ProfilerSetup

func ProfilerSetup(r *chi.Mux)

ProfilerSetup pprof route

func ReadHostID

func ReadHostID(filePath string) (string, error)

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

func RemoveSpaces

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

RemoveSpaces 去除空格项

func Rename

func Rename(old, new string) error

Rename move file

func SearchFile

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

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

func SearchFileBody

func SearchFileBody(filename, searchStr string) bool

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

func SendNoBlocking

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

SendNoBlocking 无阻塞发送

func Translation

func Translation(english string) string

Translation Translation English to Chinese

func Unzip

func Unzip(archive, target string) error

Unzip archive file to target dir

func Zip

func Zip(source, target string) error

Zip zip compressing source dir to target file

Types

type SSHClient

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

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

NewSSHClient new ssh client

func (*SSHClient) Connection

func (server *SSHClient) Connection() error

Connection 执行远程连接

Directories

Path Synopsis
etcdlock
Package etcdlock Master election using etcd.
Package etcdlock Master election using etcd.

Jump to

Keyboard shortcuts

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