utils

package
v0.0.0-...-d840a7c Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

all errors

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

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 LoadYAML

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

LoadYAML config into out interface, with defaults and validates

func MarshalYAML

func MarshalYAML(in interface{}, outPath string) error

MarshalYAML write config to file

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

func PathExists

func PathExists(path string) bool

PathExists checks path exists

func SetDefaults

func SetDefaults(ptr interface{}) error

SetDefaults set default values

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"`
	Name               string `yaml:"name" json:"name"`
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify" json:"insecureSkipVerify"` // for client, for test purpose
}

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