utils

package
v0.0.0-...-53e3d08 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AesIvLen      = 16
	AesKeyLen     = 32
	AesKeyCharSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

AES aes

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(ciphertext, key []byte) ([]byte, error)

AesDecrypt decrypts data using the specified key

func AesEncrypt

func AesEncrypt(plaintext, key []byte) ([]byte, error)

AesEncrypt encrypts data using the specified key

func AppendEnv

func AppendEnv(paramEnv map[string]string, includeHostEnv bool) []string

AppendEnv appends envs

func CalculateFileMD5

func CalculateFileMD5(fn string) (string, error)

CalculateFileMD5 calculates file MD5

func CopyFile

func CopyFile(s, t string) error

CopyFile copy data from one file to another

func DirExists

func DirExists(path string) bool

DirExists checks dir exists

func Equal

func Equal(a, b interface{}) bool

Equal compares two struct data

func FileExists

func FileExists(path string) bool

FileExists checks file exists

func GetAvailablePort

func GetAvailablePort(host string) (int, error)

GetAvailablePort finds an available port

func GetEnv

func GetEnv(key string) string

GetEnv gets env

func GetSerialNumber

func GetSerialNumber(file string) (string, error)

GetSerialNumber gets serial number from pem

func LoadYAML

func LoadYAML(path string, out interface{}) error

LoadYAML config into out interface, with defaults and validates

func NewAesKey

func NewAesKey() []byte

NewAesKey news AES key

func NewTLSClientConfig

func NewTLSClientConfig(c Certificate) (*tls.Config, error)

NewTLSClientConfig loads tls config for client

func NewTLSServerConfig

func NewTLSServerConfig(c Certificate) (*tls.Config, error)

NewTLSServerConfig loads tls config for server

func ParseURL

func ParseURL(addr string) (*url.URL, error)

ParseURL parses a url string

func PathExists

func PathExists(path string) bool

PathExists checks path exists

func RsaPrivateDecrypt

func RsaPrivateDecrypt(data, privateKey []byte) ([]byte, error)

RsaPrivateDecrypt decrypts data using private key

func RsaPrivateEncrypt

func RsaPrivateEncrypt(data, privateKey []byte) ([]byte, error)

RsaPrivateEncrypt encrypts data using private key

func RsaPublicDecrypt

func RsaPublicDecrypt(data, publicKey []byte) ([]byte, error)

RsaPublicDecrypt decrypts data using public key

func RsaPublicEncrypt

func RsaPublicEncrypt(data, publicKey []byte) ([]byte, error)

RsaPublicEncrypt encrypts data using public key

func SetDefaults

func SetDefaults(ptr interface{}) error

SetDefaults set default values

func SetEnv

func SetEnv(key, value string)

SetEnv sets env

func Trace

func Trace(name string, log func(format string, args ...interface{})) func()

Trace print elapsed time

func UnmarshalJSON

func UnmarshalJSON(in []byte, out interface{}) error

UnmarshalJSON unmarshals, defaults and validates

func UnmarshalYAML

func UnmarshalYAML(in []byte, out interface{}) error

UnmarshalYAML unmarshals, defaults and validates

func WriteFile

func WriteFile(fn string, r io.Reader) error

WriteFile writes data into file in chunk mode

Types

type Addr

type Addr struct {
	Network string `json:"network,omitempty"`
	Address string `json:"address,omitempty"`
}

Addr network ip address

type CPUInfo

type CPUInfo struct {
	Time        time.Time `json:"time,omitempty"`
	Mhz         float64   `json:"mhz,omitempty"`
	Cores       int32     `json:"cores,omitempty"`
	CacheSize   int32     `json:"cache_size,omitempty"`
	ModelName   string    `json:"model_name,omitempty"`
	PhysicalID  string    `json:"physical_id,omitempty"`
	UsedPercent float64   `json:"used_percent,omitempty"`
	Error       string    `json:"error,omitempty"`
}

CPUInfo CPU information

func GetCPUInfo

func GetCPUInfo() *CPUInfo

GetCPUInfo gets CPU information

type Certificate

type Certificate struct {
	CA       string `yaml:"ca" json:"ca"`
	Key      string `yaml:"key" json:"key"`
	Cert     string `yaml:"cert" json:"cert"`
	Insecure bool   `yaml:"insecure" json:"insecure"` // for client, for test purpose
}

Certificate certificate config for mqtt server

type DiskInfo

type DiskInfo struct {
	Time              time.Time `json:"time,omitempty"`
	Path              string    `json:"path,omitempty"`
	Fstype            string    `json:"fstype,omitempty"`
	Total             uint64    `json:"total,omitempty"`
	Free              uint64    `json:"free,omitempty"`
	Used              uint64    `json:"used,omitempty"`
	UsedPercent       float64   `json:"used_percent,omitempty"`
	InodesTotal       uint64    `json:"inodes_total,omitempty"`
	InodesUsed        uint64    `json:"inodes_used,omitempty"`
	InodesFree        uint64    `json:"inodes_free,omitempty"`
	InodesUsedPercent float64   `json:"inodes_used_percent,omitempty"`
	Error             string    `json:"error,omitempty"`
}

DiskInfo disk information

func GetDiskInfo

func GetDiskInfo(path string) *DiskInfo

GetDiskInfo gets disk information

type GPUInfo

type GPUInfo struct {
	Time  time.Time    `json:"time,omitempty"`
	GPUs  []PerGPUInfo `json:"gpus,omitempty"`
	Error string       `json:"error,omitempty"`
}

GPUInfo GPU information

func GetGPUInfo

func GetGPUInfo() *GPUInfo

GetGPUInfo gets GPU information

type HostInfo

type HostInfo struct {
	Time            time.Time `json:"time,omitempty"`
	Hostname        string    `json:"hostname,omitempty"`
	Uptime          uint64    `json:"uptime,omitempty"`
	BootTime        uint64    `json:"boot_time,omitempty"`
	ProcessNum      uint64    `json:"process_num,omitempty"`
	OS              string    `json:"os,omitempty"`
	Platform        string    `json:"platform,omitempty"`
	PlatformFamily  string    `json:"platform_family,omitempty"`
	PlatformVersion string    `json:"platform_version,omitempty"`
	KernelVersion   string    `json:"kernel_version,omitempty"`
	HostID          string    `json:"host_id,omitempty"`
	Error           string    `json:"error,omitempty"`
}

HostInfo host information

func GetHostInfo

func GetHostInfo() *HostInfo

GetHostInfo returns host information

type Interface

type Interface struct {
	Index int    `json:"index,omitempty"`
	Name  string `json:"name,omitempty"`
	MAC   string `json:"mac,omitempty"`
	Addrs []Addr `json:"addrs,omitempty"`
	Error string `json:"error,omitempty"`
}

Interface interface information

type Length

type Length struct {
	Max int64 `yaml:"max" json:"max"`
}

Length length

func (*Length) UnmarshalYAML

func (l *Length) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML customizes unmarshal

type MemInfo

type MemInfo struct {
	Time            time.Time `json:"time,omitempty"`
	Total           uint64    `json:"total,omitempty"`
	Free            uint64    `json:"free,omitempty"`
	Used            uint64    `json:"used,omitempty"`
	UsedPercent     float64   `json:"used_percent,omitempty"`
	SwapTotal       uint64    `json:"swap_total,omitempty"`
	SwapFree        uint64    `json:"swap_free,omitempty"`
	SwapUsed        uint64    `json:"swap_used,omitempty"`
	SwapUsedPercent float64   `json:"swap_used_percent,omitempty"`
	Error           string    `json:"error,omitempty"`
}

MemInfo memory information

func GetMemInfo

func GetMemInfo() *MemInfo

GetMemInfo gets memory information

type NetInfo

type NetInfo struct {
	Time       time.Time   `json:"time,omitempty"`
	Interfaces []Interface `json:"interfaces,omitempty"`
	Error      string      `json:"error,omitempty"`
}

NetInfo host information

func GetNetInfo

func GetNetInfo() *NetInfo

GetNetInfo returns host information

type PerCPUInfo

type PerCPUInfo struct {
	UsedPercent float64 `json:"used_percent,omitempty"`
}

PerCPUInfo one CPU information

type PerGPUInfo

type PerGPUInfo struct {
	Index          string  `json:"index,omitempty"`
	Model          string  `json:"model,omitempty"`
	MemTotal       uint64  `json:"mem_total,omitempty"`
	MemFree        uint64  `json:"mem_free,omitempty"`
	MemUsedPercent float64 `json:"mem_used_percent,omitempty"`
	GPUUsedPercent float64 `json:"gpu_used_percent,omitempty"`
}

PerGPUInfo one GPU information

type Tomb

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

Tomb wraps tomb.Tomb

func (*Tomb) Alive

func (t *Tomb) Alive() bool

Alive returns true if the tomb is not in a dying or dead state.

func (*Tomb) Dying

func (t *Tomb) Dying() <-chan struct{}

Dying returns the channel that can be used to wait until t.Kill is called.

func (*Tomb) Go

func (t *Tomb) Go(fs ...func() error) (err error)

Go runs functions in new goroutines.

func (*Tomb) Kill

func (t *Tomb) Kill(reason error)

Kill puts the tomb in a dying state for the given reason.

func (*Tomb) Wait

func (t *Tomb) Wait() (err error)

Wait blocks until all goroutines have finished running, and then returns the reason for their death.

If tomb does not start any goroutine, return quickly

Jump to

Keyboard shortcuts

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