util

package
v1.22.38 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnixNewLine       = "\n"
	UnixPathSeparator = "/"

	WinNewLine       = "\r\n"
	WinPathSeparator = "\\"

	LineBreak = '\n'
	EmptyStr  = ""

	OSWin   = "windows"
	OSLinux = "linux"
	OSMac   = "darwin"
)
View Source
const (
	HttpMimeJson = "application/json"

	HttpHeaderContentType = "Content-Type"
	HttpHeaderAgentToken  = "AGENT-TOKEN"
)
View Source
const (
	ZkNodeTypePersistent = int32(0)
	ZkNodeTypeEphemeral  = int32(zk.FlagEphemeral)
)

Variables

View Source
var (
	HomeDir = ""
)

Functions

func ByteToMB

func ByteToMB(bytes uint64) uint64

func BytesTrimRight

func BytesTrimRight(src []byte, trim []byte) []byte

func CopyDir

func CopyDir(src string, dst string) (err error)

func CopyFile

func CopyFile(src, dst string) (errOut error)

CopyFile The file will be created if it does not already exist. If the destination file exists, the contents will be replaced

func EnableDebugLog

func EnableDebugLog()

func FailOnError

func FailOnError(err error, msg string)

FailOnError exit program with err

func GetEnv

func GetEnv(env, def string) string

func GetType

func GetType(v interface{}) reflect.Type

GetType get type of pointer

func GetValue

func GetValue(v interface{}) reflect.Value

func HasError

func HasError(err error) bool

func HasString

func HasString(s string) bool

func IndexOfFirstSpace

func IndexOfFirstSpace(str string) int

func IsByteStartWith

func IsByteStartWith(src []byte, start []byte) bool

func IsEmptyString

func IsEmptyString(s string) bool

IsEmptyString to check input s is empty

func IsFileExists

func IsFileExists(path string) bool

func IsFileExistsAndReturnFileInfo

func IsFileExistsAndReturnFileInfo(path string) (os.FileInfo, bool)

func IsLinux

func IsLinux() bool

func IsMac

func IsMac() bool

func IsPointerType

func IsPointerType(v interface{}) bool

IsPointerType to check the input v is pointer type

func IsWindows

func IsWindows() bool

func LogDebug

func LogDebug(format string, a ...interface{})

func LogIfError

func LogIfError(err error) bool

func LogInfo

func LogInfo(format string, a ...interface{})

func LogInit

func LogInit()

func LogWarn

func LogWarn(format string, a ...interface{})

func OS

func OS() string

func PanicIfErr

func PanicIfErr(err error)

func PanicIfNil

func PanicIfNil(obj interface{}, msg string)

func ParseString

func ParseString(src string) string

ParseString parse string which include system env variable

func ParseStringWithSource

func ParseStringWithSource(src string, source map[string]string) string

func PointerBoolean

func PointerBoolean(val bool) *bool

func RecoverPanic

func RecoverPanic(handler func(e error))

func TrimLeftString

func TrimLeftString(src, trim string) string

func UTF16BytesToString

func UTF16BytesToString(b []byte, o binary.ByteOrder) string

func Unzip

func Unzip(src string, dest string) (out error)

func Wait

func Wait(group *sync.WaitGroup, timeout time.Duration) bool

func Zip

func Zip(src, dest, separator string) (out error)

Types

type ZkCallbacks

type ZkCallbacks struct {
	OnDisconnected func()
}

type ZkClient

type ZkClient struct {
	Callbacks *ZkCallbacks
	// contains filtered or unexported fields
}

func NewZkClient

func NewZkClient() *ZkClient

func (*ZkClient) Close

func (client *ZkClient) Close()

Close release connection

func (*ZkClient) Connect

func (client *ZkClient) Connect(host string) error

Connect zookeeper host

func (*ZkClient) Create

func (client *ZkClient) Create(path string, nodeType int32, data string) (string, error)

Create create node with node type and data

func (*ZkClient) Data

func (client *ZkClient) Data(path string) (string, error)

func (*ZkClient) Delete

func (client *ZkClient) Delete(path string) error

func (*ZkClient) Exist

func (client *ZkClient) Exist(path string) (bool, error)

Exist check the node is exist

Jump to

Keyboard shortcuts

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