Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.0.0-...-84cc4f8 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: Apache-2.0 Imports: 32 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 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 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 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) error

SetEnv sets env

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 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 Disk

type Disk struct {
	Total string
	Free  string
}

Disk Disk

func GetDisk

func GetDisk() (*Disk, error)

GetDisk gets disk information

type Gpu

type Gpu struct {
	ID     string
	Model  string
	Memory Mem
}

Gpu Gpu

func GetGpu

func GetGpu() ([]Gpu, error)

GetGpu gets gpu 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 Mem

type Mem struct {
	Total string
	Free  string
}

Mem Mem

func GetMem

func GetMem() (*Mem, error)

GetMem gets memory information

type Swap

type Swap struct {
	Total string
	Free  string
}

Swap Swap

func GetSwap

func GetSwap() (*Swap, error)

GetSwap gets swap space 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