utils

package
v0.0.0-...-005948e Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrContains

func ArrContains(a, b []string) bool

func CalculatePercentageInt32

func CalculatePercentageInt32(part, total int32) int32

func DecodeCidr

func DecodeCidr(ipCidr string) string

func DecodeString

func DecodeString(content string, keyVal map[string]string) string

func DecodeYaml

func DecodeYaml(yamlContent string, keyVal map[string]string) string

func DeserializeFromBase64

func DeserializeFromBase64(data string, msg proto.Message) error

func DownloadFile

func DownloadFile(rawURL string) (string, error)

func GenerateCIDR

func GenerateCIDR(ip string, prefixLen int) (string, error)

func GenerateSubnet

func GenerateSubnet(vpcCIDR string, exitsSubnets []string) (string, error)

func GenerateSubnets

func GenerateSubnets(vpcCIDR string, subnetCount int) ([]string, error)

func GetFilePathAndName

func GetFilePathAndName(path string) (string, string)

func GetFromContext

func GetFromContext(ctx context.Context) map[string]string

func GetFromContextByKey

func GetFromContextByKey(ctx context.Context, key MatedataKey) string

func GetLogFilePath

func GetLogFilePath() string

func GetServerStoragePathByNames

func GetServerStoragePathByNames(packageNames ...string) string

func Int64Ptr

func Int64Ptr(i int64) *int64

func IsFileExist

func IsFileExist(path string) bool

func IsSubnetOverlap

func IsSubnetOverlap(cidr1, cidr2 string) (bool, error)

func IsValidKubernetesName

func IsValidKubernetesName(name string) bool

check string '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'

func LabelsToMap

func LabelsToMap(labels string) map[string]string

labels (string) to map[string]string

func MapToLabels

func MapToLabels(m map[string]string) string

map[string]string to labels (string)

func MapToString

func MapToString(m map[string]string) string

MapToString converts a map[string]string to a comma-separated string

func Md5

func Md5(str string) string

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

MergeMaps combines multiple string maps into a single map. If there are duplicate keys, the value from the later map takes precedence.

func NewLog

func NewLog(conf *conf.Bootstrap) *logtool

func RangeIps

func RangeIps(startIp, endIp string) []string

example: startIp 192.168.0.1 endIp 192.168.0.254, return 192.168.0.1 192.168.0.2 .... 192.168.0.254

func ReadLastNLines

func ReadLastNLines(file *os.File, n int) (string, error)

ReadLastNLines reads the last n lines from a file.

func RemoveDuplicatesInt64

func RemoveDuplicatesInt64(slice []int64) []int64

func SerializeToBase64

func SerializeToBase64(msg proto.Message) (string, error)

func StringPtr

func StringPtr(s string) *string

func StringToMap

func StringToMap(s string) map[string]string

StringToMap converts a comma-separated string back to map[string]string

func StringValue

func StringValue(s *string) string

func StructTransform

func StructTransform(a, b any) error

func TransferredMeaning

func TransferredMeaning(data any, fileDetailPath string) (tmpFile string, err error)

func TransferredMeaningString

func TransferredMeaningString(data any, fileDetailPath string) (string, error)

func WriteFile

func WriteFile(filePath, content string) error

Types

type Bash

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

func NewBash

func NewBash(log *log.Helper) *Bash

func (*Bash) RunCommand

func (b *Bash) RunCommand(command string, args ...string) (output string, err error)

func (*Bash) RunCommandWithLogging

func (b *Bash) RunCommandWithLogging(command string, args ...string) error

type File

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

func NewFile

func NewFile(path, name string, resume bool) (*File, error)

func (*File) ClearFileContent

func (f *File) ClearFileContent() error

func (*File) Close

func (f *File) Close() error

func (*File) GetFileFullPath

func (f *File) GetFileFullPath() string

func (*File) GetFileName

func (f *File) GetFileName() string

func (*File) GetFilePath

func (f *File) GetFilePath() string

func (*File) Read

func (f *File) Read() ([]byte, error)

func (*File) Write

func (f *File) Write(chunk []byte) error

type GrpcConn

type GrpcConn struct {
	Conn *grpcConnect.ClientConn
	Ctx  context.Context
}

func (*GrpcConn) Close

func (g *GrpcConn) Close()

func (*GrpcConn) OpenGrpcConn

func (g *GrpcConn) OpenGrpcConn(ctx context.Context, addr string, port int32, timeoutsecond int64) (*GrpcConn, error)

type MatedataKey

type MatedataKey string
const (
	ServiceNameKey    MatedataKey = "service"
	ServiceVersionKey MatedataKey = "version"
	RuntimeKey        MatedataKey = "runtime"
	OSKey             MatedataKey = "os"
	ArchKey           MatedataKey = "arch"
	ConfKey           MatedataKey = "conf"
	ConfDirKey        MatedataKey = "confdir"
)

func (MatedataKey) String

func (m MatedataKey) String() string

type RemoteBash

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

func NewRemoteBash

func NewRemoteBash(server Server, shellDir string, log *log.Helper) *RemoteBash

func (*RemoteBash) ExecShell

func (s *RemoteBash) ExecShell(shellName string, args ...string) (stdout string, err error)

func (*RemoteBash) ExecShellLogging

func (s *RemoteBash) ExecShellLogging(shellName string, args ...string) error

func (*RemoteBash) GetRootHome

func (s *RemoteBash) GetRootHome() (string, error)

func (*RemoteBash) GetUserHome

func (s *RemoteBash) GetUserHome() (string, error)

func (*RemoteBash) Run

func (s *RemoteBash) Run(command string, args ...string) (stdout string, err error)

func (*RemoteBash) RunWithLogging

func (s *RemoteBash) RunWithLogging(command string, args ...string) error

RunWithLogging runs a command and logs its output

func (*RemoteBash) SftpFile

func (s *RemoteBash) SftpFile(localFile, remoteFile string) error

type Server

type Server struct {
	Name       string `json:"name,omitempty"`
	User       string `json:"user,omitempty"`
	Host       string `json:"host,omitempty"`
	Port       int32  `json:"port,omitempty"`
	PrivateKey string `json:"private_key,omitempty"`
}

Jump to

Keyboard shortcuts

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