util

package
v5.0.4-release+incompa... Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: LGPL-3.0 Imports: 32 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 BytesSliceEqual

func BytesSliceEqual(a, b []byte) bool

BytesSliceEqual BytesSliceEqual

func CheckAndCreateDir

func CheckAndCreateDir(path string) error

CheckAndCreateDir check and create dir

func CheckAndCreateDirByMode

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

CheckAndCreateDirByMode 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 CopyFile

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

func CreateFileHash(sourceFile, hashfile string) error

CreateFileHash compute sourcefile hash and write hashfile

func CreateHashString

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

CreateHashString create hash string

func CreateHostID

func CreateHostID() (string, error)

CreateHostID create host id by mac addr

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 GetCurrentDir

func GetCurrentDir() string

GetCurrentDir get current dir

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 IsDir

func IsDir(path string) (bool, error)

IsDir path is dir

func IsHaveFile

func IsHaveFile(path string) bool

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

func LocalIP

func LocalIP() (net.IP, error)

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

func MergeDir

func MergeDir(fromdir, todir string) error

MergeDir MergeDir if Subdirectories already exist, Don't replace

func NewUUID

func NewUUID() string

NewUUID 创建无-的32位uuid

func OpenOrCreateFile

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

OpenOrCreateFile open or create file

func ParseVariable

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

ParseVariable parse and replace variable in source str

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 StdCopy

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

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

StringArrayContains string array contains

func ToByte

func ToByte(v string) []byte

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

func ToString

func ToString(b []byte) string

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

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 PipeCommand

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

PipeCommand PipeCommand

func NewPipeCommand

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

NewPipeCommand new pipe commands

func (*PipeCommand) GetFinalStderr

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

GetFinalStderr get final command stderr reader

func (*PipeCommand) GetFinalStdout

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

GetFinalStdout get final command stdout reader

func (*PipeCommand) Run

func (p *PipeCommand) Run() error

Run Run

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 执行远程连接

type StdType

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

type TimeVersion string

TimeVersion time version

func NewTimeVersion

func NewTimeVersion() TimeVersion

NewTimeVersion return version string by time

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