utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConvTypeRaw = "raw"
	ConvTypeHex = "hex"
)
View Source
const (
	MatchRegex         = "reg"
	MatchEqual         = "eq"
	MatchNotEqual      = "nq"
	MatchStartsWith    = "startswith"
	MatchNotStartsWith = "nstartswith"
	MatchEndsWith      = "endswith"
	MatchNotEndsWith   = "nendswith"
	MatchContains      = "in"
	MatchNotContains   = "nin"
	MatchWildcard      = "wildcard"
	MatchHex           = "hex"
)

Variables

View Source
var EncodingMaps map[string]encoding.Encoding

EncodingMaps :

View Source
var ErrScriptTimeout = fmt.Errorf("run script timeout")

ErrScriptTimeout : the error indicate that script run timeout

Functions

func AssemblePipes

func AssemblePipes(cmds []*exec.Cmd, stdin io.Reader, stdout io.Writer) []*exec.Cmd

AssemblePipes Pipe stdout of each command into stdin of next

func AssemblePipesWithoutErr

func AssemblePipesWithoutErr(cmds []*exec.Cmd, stdin io.Reader, stdout io.Writer) []*exec.Cmd

AssemblePipesWithoutErr Pipe stdout of each command into stdin of next and not use stderr

func CleanCompositeParamList

func CleanCompositeParamList(configs ...define.CompositeParam) error

CleanCompositeParamList 清洗符合接口定义格式的对象,是CleanCompositableConfigs的优化版

func ClearTempFile

func ClearTempFile(pattern string) error

ClearTempFile clear temp file by pattern

func ConvertHexStringToBytes

func ConvertHexStringToBytes(data string) ([]byte, error)

ConvertHexStringToBytes :

func ConvertStringToBytes

func ConvertStringToBytes(data string, typ string) ([]byte, error)

ConvertStringToBytes :

func CreateTempFile

func CreateTempFile(pattern string) (*os.File, error)

CreateTempFile get temp file by pattern

func FilterIpsWithIpType

func FilterIpsWithIpType(ips []string, ipType DomainType) []string

通过ipType筛选ip列表,提取指定类型的ip

func GeneratorHashKey

func GeneratorHashKey(names []string) string

GeneratorHashKey

func GetDurationSecondsSince

func GetDurationSecondsSince(t time.Time) float64

func GetPtrByName

func GetPtrByName(object interface{}, attr string) (interface{}, bool)

GetPtrByName :

func GetRootDevices

func GetRootDevices() (int64, int64, error)

func GetValueByName

func GetValueByName(object interface{}, attr string) (reflect.Value, bool)

GetValueByName :

func HasTempDir

func HasTempDir() bool

HasTempDir if temp dir exists

func HashIt

func HashIt(object interface{}) string

HashIt : hash an object

func InitTempDir

func InitTempDir(clear bool) (string, error)

InitTempDir initialize temp dir

func IsLinuxOS

func IsLinuxOS() bool

func IsMatch

func IsMatch(matchType string, content []byte, expect []byte) bool

IsMatch :

func IsMatchString

func IsMatchString(matchType string, content string, expect string) bool

IsMatchString :

func NewDecoder

func NewDecoder(name string) *encoding.Decoder

NewDecoder :

func NewEncoder

func NewEncoder(name string) *encoding.Encoder

NewEncoder :

func ParseCmdline2Cmds

func ParseCmdline2Cmds(cmdline string, userEnvs map[string]string) ([][]string, error)

ParseCmdline2Cmds parse command line to serial of sub command

func PathExist

func PathExist(path string) bool

PathExist : judge path exist or not

func PidStoreFile

func PidStoreFile() string

func ReadFileTail

func ReadFileTail(p string, size int64) ([]byte, error)

func RealReflectValue

func RealReflectValue(v reflect.Value) reflect.Value

RealReflectValue :

func RecoverFor

func RecoverFor(fn func(error))

RecoverFor : callback for recover

func RunCmds

func RunCmds(cmds []*exec.Cmd, notify chan error)

RunCmds Run series of piped commands

func RunString

func RunString(ctx context.Context, s string, userEnvs map[string]string) (string, error)

RunString Convert a shell command with a series of pipes into correspondingly piped list of *exec.Cmd If an arg has spaces, this will fail

func RunStringWithoutErr

func RunStringWithoutErr(ctx context.Context, s string, userEnvs map[string]string) (string, error)

RunStringWithoutErr Convert a shell command with a series of pipes into correspondingly piped list of *exec.Cmd If an arg has spaces, this will fail not print error message

func SafeReflectValueAddrInterface

func SafeReflectValueAddrInterface(v reflect.Value) interface{}

SafeReflectValueAddrInterface :

func SafeReflectValueInterface

func SafeReflectValueInterface(v reflect.Value) interface{}

SafeReflectValueInterface :

func SetLinuxCGroup

func SetLinuxCGroup(name string, blockIO SpecBlockIO) error

func WildcardToRegex

func WildcardToRegex(pattern string) string

WildcardToRegex :

Types

type Atomic

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

Atomic :

func (*Atomic) Run

func (a *Atomic) Run(f AtomicFunc)

Run :

type AtomicFunc

type AtomicFunc func()

AtomicFunc :

type DomainType

type DomainType int32
const (
	Domain DomainType = 0
	V4     DomainType = 4
	V6     DomainType = 6
)

func CheckIpOrDomainValid

func CheckIpOrDomainValid(addr string) DomainType

判断addr是否为有效的ipv4 ipv6 或者域名 返回值: 0-有效域名 4-有效ipv4 6-有效ipv6

type GetEnver

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

GetEnver :

func (*GetEnver) GetEnv

func (ge *GetEnver) GetEnv(key string) string

GetEnv :

type HookFunction

type HookFunction func(ctx context.Context)

HookFunction :

type HookManager

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

HookManager :

func (*HookManager) Add

func (m *HookManager) Add(hook HookFunction)

Add :

func (*HookManager) Apply

func (m *HookManager) Apply(ctx context.Context)

Apply :

type RpmResult

type RpmResult struct {
	Package string `json:"package"`
	Verify  string `json:"verify"`
}

func RpmVerify

func RpmVerify(ctx context.Context) ([]RpmResult, error)

type SpecBlockIO

type SpecBlockIO struct {
	Major      int64
	Minor      int64
	WriteBytes uint64
	ReadBytes  uint64
	WriteIOps  uint64
	ReadIOps   uint64
}

Jump to

Keyboard shortcuts

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