utils

package
v0.0.0-...-e0ce882 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Equal

func Equal(a, b interface{}) bool

Equal compares two struct data

func GetEnv

func GetEnv(key string) string

GetEnv gets env

func GetPortAvailable

func GetPortAvailable(host string) (int, error)

GetPortAvailable finds an available port

func MakeErrorPayload

func MakeErrorPayload(p *packet.Publish, err error) []byte

MakeErrorPayload makes error payload

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

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