utils

package
v2.0.61 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 29 Imported by: 55

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStillAlive = tb.ErrStillAlive
	ErrDying      = tb.ErrDying
)

all errors

View Source
var (
	VERSION  = "unknown"
	REVISION = "unknown"
)

Compile parameter

Functions

func CalculateBase64

func CalculateBase64(s string) string

CalculateBase64 calculates base64 encoding value of target string

func CalculateFileMD5

func CalculateFileMD5(fn string) (string, error)

CalculateFileMD5 calculates file MD5 in hex format

func CheckPortAvailable added in v2.0.46

func CheckPortAvailable(ip string, port int) bool

func CopyFile

func CopyFile(s, t string) error

CopyFile copy data from one file to another

func CreateSymlink(target, symlink string) error

CreateSymlink create symlink of target

func DirExists

func DirExists(path string) bool

DirExists checks dir exists

func FileExists

func FileExists(path string) bool

FileExists checks file exists

func GetAvailablePort added in v2.0.42

func GetAvailablePort(host string) (int, error)

GetAvailablePort finds an available port

func LoadYAML

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

LoadYAML config into out interface, with defaults and validates

func NewTLSConfigClient

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

NewTLSConfigClient loads tls config for client

func NewTLSConfigServer

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

NewTLSConfigServer loads tls config for server

func ParseEnv

func ParseEnv(data []byte) ([]byte, error)

ParseEnv parses env

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 PrintVersion added in v2.0.13

func PrintVersion()

func SetDefaults

func SetDefaults(ptr interface{}) error

SetDefaults set default values

func Tar

func Tar(sources []string, destination string) error

Tar tar source files to destination file

func Trace

func Trace(f func(string, ...log.Field), msg string, fields ...log.Field) 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 Untar

func Untar(source, destination string) error

Untar untar source file to destination

func Unzip

func Unzip(source, destination string) error

Unzip unzip source file to destination

func Version

func Version() string

func WriteFile

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

WriteFile writes data into file in chunk mode

func Zip

func Zip(sources []string, destination string) error

Zip zip source files to destination file

Types

type Certificate

type Certificate struct {
	CA                 string `yaml:"ca" json:"ca"`
	Key                string `yaml:"key" json:"key"`
	Cert               string `yaml:"cert" json:"cert"`
	Name               string `yaml:"name" json:"name"`
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify" json:"insecureSkipVerify"` // for client, for test purpose
	tls.ClientAuthType `yaml:"clientAuthType" json:"clientAuthType"`
}

Certificate certificate config for server Name : serverNameOverride, same to CommonName in server.pem if Name == "" , link would not verifies the server's certificate chain and host name AuthType : declares the policy the server will follow for TLS Client Authentication

type Length

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

Length length ! Length is deprecated, please to use Size

func (*Length) MarshalYAML

func (l *Length) MarshalYAML() (interface{}, error)

MarshalYAML implements the Marshaller interface

func (*Length) UnmarshalYAML

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

UnmarshalYAML customizes unmarshal

type Size

type Size int64

Size size

func (Size) MarshalJSON

func (s Size) MarshalJSON() ([]byte, error)

MarshalJSON customizes marshal

func (Size) MarshalYAML

func (s Size) MarshalYAML() (interface{}, error)

MarshalYAML customizes marshal

func (*Size) UnmarshalJSON

func (s *Size) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes unmarshal

func (*Size) UnmarshalYAML

func (s *Size) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML customizes unmarshal

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

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

Dead returns the channel that can be used to wait until all goroutines have finished running.

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

func (t *Tomb) Err() (reason error)

Err returns the death reason, or ErrStillAlive if the tomb is not in a dying or dead state.

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