utils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClusterNotExist = fmt.Errorf("no cluster exist")

Functions

func AppendFile

func AppendFile(fileName string, content string) error

func AppendIPList

func AppendIPList(src, dst []string) []string

func AssemblyIPList added in v0.5.0

func AssemblyIPList(args *string) error

func AtomicWriteFile added in v0.3.0

func AtomicWriteFile(filepath string, data []byte, perm os.FileMode) (err error)

func CheckCmdIsExist

func CheckCmdIsExist(cmd string) (string, bool)

func CheckIP added in v0.5.0

func CheckIP(i string) bool

func CleanDir

func CleanDir(dir string)

func CleanDirs

func CleanDirs(dirs ...string)

func CleanFile

func CleanFile(file *os.File)

func CleanFiles

func CleanFiles(file ...string) error

func Cmd

func Cmd(name string, args ...string) error

func CmdOutput

func CmdOutput(name string, args ...string) ([]byte, error)

func CompareIP added in v0.5.0

func CompareIP(v1, v2 string) (int, error)

func ContainList added in v0.5.2

func ContainList(list []string, toComplete string) (containerList []string)

func CopyDir

func CopyDir(srcPath, dstPath string) error

cp -r /roo/test/* /tmp/abc

func CopySingleFile

func CopySingleFile(src, dst string) (int64, error)

cp a.txt /tmp/mytest/a.txt

func CountDirFiles

func CountDirFiles(dirName string) int

func DecodeCluster added in v0.3.4

func DecodeCluster(filepath string) (clusters []v1.Cluster, err error)

func DecodeConfigs added in v0.3.4

func DecodeConfigs(filepath string) (configs []v1.Config, err error)

func DecodePlugins added in v0.3.4

func DecodePlugins(filepath string) (plugins []v1.Plugin, err error)

func DedupeStrSlice added in v0.6.0

func DedupeStrSlice(in []string) []string

func DisassembleIPList added in v0.5.0

func DisassembleIPList(arg string) (res []string)

func ExecutableFilePath

func ExecutableFilePath() string

func FileMD5

func FileMD5(path string) (string, error)

FileMD5 count file md5

func GenUniqueID

func GenUniqueID(n int) string

GenUniqueId: gen uuid

func GetClusterFromFile added in v0.5.2

func GetClusterFromFile(filepath string) (cluster *v2.Cluster, err error)

func GetDefaultClusterName added in v0.5.0

func GetDefaultClusterName() (string, error)

func GetDiffHosts

func GetDiffHosts(hostsOld, hostsNew []string) (add, sub []string)

func GetDockerAuthInfoFromDocker added in v0.1.5

func GetDockerAuthInfoFromDocker(domain string) (types.AuthConfig, error)

func GetFileSize added in v0.5.0

func GetFileSize(path string) (size int64, err error)

func GetFilesSize added in v0.5.0

func GetFilesSize(paths []string) (int64, error)

func GetHostIP

func GetHostIP(host string) string

use only one

func GetHostIPAndPortOrDefault added in v0.3.0

func GetHostIPAndPortOrDefault(host, Default string) (string, string)

func GetHostIPSlice

func GetHostIPSlice(hosts []string) (res []string)

func GetLocalHostAddresses added in v0.6.1

func GetLocalHostAddresses() (*[]net.Addr, error)

func GetSSHHostIPAndPort added in v0.3.0

func GetSSHHostIPAndPort(host string) (string, string)

func IPToInt added in v0.5.0

func IPToInt(v string) *big.Int

func InList added in v0.5.2

func InList(key string, slice []string) bool

func IsDir

func IsDir(path string) bool

func IsExist added in v0.3.0

func IsExist(fileName string) bool

func IsFileContent added in v0.5.0

func IsFileContent(fileName string, content string) bool

func IsFileExist

func IsFileExist(filename string) bool

func IsHostPortExist added in v0.5.0

func IsHostPortExist(protocol string, hostname string, port int) bool

func IsInContainer added in v0.3.0

func IsInContainer() bool

func IsLocalIP added in v0.3.0

func IsLocalIP(ip string, addrs *[]net.Addr) bool

func Lgetxattr added in v0.3.3

func Lgetxattr(path string, attr string) ([]byte, error)

Lgetxattr retrieves the value of the extended attribute identified by attr and associated with the given path in the file system. It will returns a nil slice and nil error if the xattr is not set.

func Lsetxattr added in v0.3.3

func Lsetxattr(path string, attr string, data []byte, flags int) error

Lsetxattr sets the value of the extended attribute identified by attr and associated with the given path in the file system.

func MD5

func MD5(body []byte) string

func MarshalConfigsToYaml added in v0.6.0

func MarshalConfigsToYaml(in ...interface{}) ([]byte, error)

func MarshalConfigsYaml added in v0.6.0

func MarshalConfigsYaml(configs ...interface{}) ([]byte, error)

func MarshalJSONToFile added in v0.6.0

func MarshalJSONToFile(file string, obj interface{}) error

func MarshalYamlToFile

func MarshalYamlToFile(file string, obj interface{}) error

func MkDirs added in v0.5.0

func MkDirs(dirs ...string) error

func MkFileFullPathDir

func MkFileFullPathDir(fileName string) error

file ./test/dir/xxx.txt if dir ./test/dir not exist, create it

func MkTmpFile added in v0.3.0

func MkTmpFile(path string) (*os.File, error)

func MkTmpdir

func MkTmpdir() (string, error)

func Mkdir

func Mkdir(dirName string) error

func NextIP added in v0.5.0

func NextIP(ip string) net.IP

func NotIn

func NotIn(key string, slice []string) bool

func NotInIPList added in v0.3.0

func NotInIPList(key string, slice []string) bool

func ParseCIDRString added in v0.1.5

func ParseCIDRString(s string) (string, error)

Parse CIDR Fix to Standard CIDR

func ReadAll

func ReadAll(fileName string) ([]byte, error)

ReadAll read file content

func ReadLines added in v0.3.0

func ReadLines(fileName string) ([]string, error)

func RecursionCopy

func RecursionCopy(src, dst string) error

copy a.txt /var/lib/a.txt copy /root/test/abc /tmp/abc

func RecursionHardLink(src, dst string) error

func RecursionHardLinkDir added in v0.3.3

func RecursionHardLinkDir(src, dst string, modTimes *[]*tar.Header) error

func ReduceIPList

func ReduceIPList(src, dst []string) []string

func RemoveDuplicate added in v0.3.0

func RemoveDuplicate(list []string) []string

func RemoveFileContent

func RemoveFileContent(fileName string, content string) error

func RemoveIPList added in v0.6.0

func RemoveIPList(src, dst []string) []string

func Retry added in v0.5.0

func Retry(tryTimes int, trySleepTime time.Duration, action func() error) error

func Reverse added in v0.3.4

func Reverse(s []string) []string

func RunSimpleCmd

func RunSimpleCmd(cmd string) (string, error)

func SaveClusterInfoToFile added in v0.6.0

func SaveClusterInfoToFile(cluster runtime.Object, clusterName string) error

func SaveClusterfile added in v0.3.0

func SaveClusterfile(cluster *v1.Cluster) error

func SetDockerConfig

func SetDockerConfig(hostname, username, password string) error

func SetRootfsBinToSystemEnv added in v0.5.2

func SetRootfsBinToSystemEnv(rootfs string) error

func SortIPList

func SortIPList(iplist []string)

func UnmarshalYamlFile

func UnmarshalYamlFile(file string, obj interface{}) error

func WrapExecResult added in v0.6.0

func WrapExecResult(host, command string, output []byte, err error) error

func WriteFile

func WriteFile(fileName string, content []byte) error

func YamlMatcher added in v0.6.0

func YamlMatcher(path string) bool

Types

type AuthItem

type AuthItem struct {
	Auth string `json:"auth"`
}

type CIDR added in v0.1.5

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

https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing CIDR doc: IPv4 network Addr/prefixLength 192.168.1.0/24 IPv6 network Addr/prefixLength 2001:db8::/64

func ParseCIDR added in v0.1.5

func ParseCIDR(s string) (*CIDR, error)

Parse CIDR net range

func (CIDR) CIDR added in v0.1.5

func (c CIDR) CIDR() string

Fixed CIDR String

func (CIDR) IP added in v0.1.5

func (c CIDR) IP() string

Get IP

func (CIDR) IsIPv4 added in v0.1.5

func (c CIDR) IsIPv4() bool

Is IPv4

func (CIDR) IsIPv6 added in v0.1.5

func (c CIDR) IsIPv6() bool

Is IPv6

func (CIDR) Mask added in v0.1.5

func (c CIDR) Mask() string

SubnetMask

func (CIDR) MaskSize added in v0.1.5

func (c CIDR) MaskSize() (ones, bits int)

Get Mask Size

func (CIDR) Network added in v0.1.5

func (c CIDR) Network() string

Get Network Addr

type DockerInfo

type DockerInfo struct {
	Auths map[string]AuthItem `json:"auths"`
}

func DockerConfig

func DockerConfig() (*DockerInfo, error)

func (DockerInfo) DecodeDockerAuth

func (d DockerInfo) DecodeDockerAuth(hostname string) (string, string, error)

func (DockerInfo) LocalDockerAuth

func (d DockerInfo) LocalDockerAuth(hostname string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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