util

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateMAC

func CalculateMAC(message, key []byte) []byte

CalculateMAC calculate the HMAC

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake convert CamelCase to SnakeCase

func DeepCopyMapParam

func DeepCopyMapParam(param map[string]interface{}) map[string]interface{}

DeepCopyMapParam returns a deep copied map param object

func DeepCopyParam

func DeepCopyParam(param interface{}) interface{}

DeepCopyParam returns a deep copied json param object

func FileExists added in v1.8.0

func FileExists(filename string) bool

FileExists checks if a file exists

func GetBoolParam

func GetBoolParam(param map[string]interface{}, name string) (bool, error)

GetBoolParam get the bool param from the map

func GetFloatParam added in v1.8.4

func GetFloatParam(param map[string]interface{}, name string) (float64, error)

GetFloatParam get the float param from the map

func GetIntParam

func GetIntParam(param map[string]interface{}, name string) (int, error)

GetIntParam get the int param from the map

func GetMapParam

func GetMapParam(param map[string]interface{}, name string) (map[string]interface{}, error)

GetMapParam get the map param from the map

func GetNestedMapValue

func GetNestedMapValue(param map[string]interface{}, nestedKey string) (interface{}, error)

GetNestedMapValue get the value of a nested key from the map map["a/b/c"] = map["a"]["b"]["c"]

func GetStringParam

func GetStringParam(param map[string]interface{}, name string) (string, error)

GetStringParam get the string param from the map

func GetStringSliceParam

func GetStringSliceParam(param map[string]interface{}, name string) ([]string, error)

GetStringSliceParam get the string slice param from the map (string or slice of strings)

func InterfaceMapToStringMap

func InterfaceMapToStringMap(param interface{}) interface{}

InterfaceMapToStringMap will only keep map with string keys

func JSONToMap

func JSONToMap(text []byte) (map[string]interface{}, error)

JSONToMap convert json to map

func MergeMapParam

func MergeMapParam(mapOrigin, mapNew map[string]interface{})

MergeMapParam merges the two maps

func RunCmd

func RunCmd(args []string, cwd string, env []string, background bool, stdout, stderr *string) (int, error)

RunCmd will open the sub process

func SHA256Sum

func SHA256Sum(r io.Reader) ([]byte, error)

SHA256Sum calculate the sha256 checksum from the Reader

func SHA256SumFile

func SHA256SumFile(fn string) ([]byte, error)

SHA256SumFile calculate the sha256 checksum from the file

func ValidateMAC

func ValidateMAC(message, messageMAC, key []byte) bool

ValidateMAC checks the validation of message based on the key

Types

type BaseLogger

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

BaseLogger is a basic struct implement LoggerSetter

func (*BaseLogger) Debugf

func (l *BaseLogger) Debugf(f string, v ...interface{})

Debugf log debug output

func (*BaseLogger) Errorf

func (l *BaseLogger) Errorf(f string, v ...interface{})

Errorf log error output

func (*BaseLogger) Infof

func (l *BaseLogger) Infof(f string, v ...interface{})

Infof log info output

func (*BaseLogger) SetLogger

func (l *BaseLogger) SetLogger(logger interface{})

SetLogger will set logger

func (*BaseLogger) Warnf

func (l *BaseLogger) Warnf(f string, v ...interface{})

Warnf log warn output

type ExeGit

type ExeGit struct {
	BaseLogger
	WorkDir string
}

ExeGit executes script from git repository

func (*ExeGit) Execute

func (exe *ExeGit) Execute(param map[string]interface{}) (map[string]interface{}, error)

Execute will executes script from git repo

func (*ExeGit) WorkRepoDir added in v1.8.3

func (exe *ExeGit) WorkRepoDir() string

WorkRepoDir return the run directory

func (*ExeGit) WorkRunDir

func (exe *ExeGit) WorkRunDir() string

WorkRunDir return the run directory

type HTTPServer

type HTTPServer struct {
	BaseLogger
	UnixSocket   string
	Host         string
	Port         int
	ServerHeader string
	ValidateFunc func(*http.Request, []byte) error
	ProcessFunc  func(http.ResponseWriter, *http.Request, []byte)
	// contains filtered or unexported fields
}

HTTPServer is a trigger which will listen to http request

func (*HTTPServer) Start

func (h *HTTPServer) Start()

Start the http server

func (*HTTPServer) Stop

func (h *HTTPServer) Stop()

Stop the http server

type PrefixLogger

type PrefixLogger struct {
	Logger herald.Logger
	Prefix string
}

PrefixLogger automatically add prefix for logger

func (*PrefixLogger) Debugf

func (l *PrefixLogger) Debugf(f string, v ...interface{})

Debugf log debug output

func (*PrefixLogger) Errorf

func (l *PrefixLogger) Errorf(f string, v ...interface{})

Errorf log error output

func (*PrefixLogger) Infof

func (l *PrefixLogger) Infof(f string, v ...interface{})

Infof log info output

func (*PrefixLogger) Warnf

func (l *PrefixLogger) Warnf(f string, v ...interface{})

Warnf log warn output

type SimpleFormatter

type SimpleFormatter struct {
	TimeFormat string
	Utc        bool
}

SimpleFormatter is a simple formatter for logrus

func (SimpleFormatter) Format

func (f SimpleFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format the log string

Jump to

Keyboard shortcuts

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