util

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const FullMatch = "match"

FullMatch is the key of the "Result" which contains the initial full string of the matching process todo remove this old shitty magic...

Variables

This section is empty.

Functions

func CompileRegexp

func CompileRegexp(pattern string) *regexp.Regexp

CompileRegexp compiles a regexp to a unified regexp layout: - case insensitive - always match a full line -> implicitly adds "^" and "$"

func CompileTemplate

func CompileTemplate(temp string) (*template.Template, error)

CompileTemplate pre compiles a template and returns an error if an function is not available etc

func EvalTemplate

func EvalTemplate(temp *template.Template, params Parameters) (string, error)

EvalTemplate renders the template

func FormatBytes added in v1.6.0

func FormatBytes(bytes uint64) string

func FormatDuration

func FormatDuration(duration time.Duration) string

FormatDuration shortens a duration string representation. e.g. "12m1.231001s" -> "12m1s"

func GetTemplateFunctions added in v1.7.0

func GetTemplateFunctions() template.FuncMap

GetTemplateFunctions returns a list of the currently available template functions which can be used in definedCommands or user specific commands

func ParseDuration

func ParseDuration(input string) (time.Duration, error)

ParseDuration also allowes other duration modifier like "min" or "sec" e.g. 12min10sec -> 12m10s

Example
fmt.Println(ParseDuration("12min1sec"))
Output:

12m1s <nil>

func RandString added in v1.3.0

func RandString(n int) string

RandString get random string containing just letters and numbers todo search better crypto/ function to generate such string

func RegexpResultToParams

func RegexpResultToParams(re *regexp.Regexp, match []string) map[string]string

RegexpResultToParams converts a regexp result into a simple string map...kind of deprecated

func RegisterFunctions

func RegisterFunctions(funcMap template.FuncMap)

RegisterFunctions will add a function to any template renderer

Types

type IncreasingDelay added in v1.6.0

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

func GetIncreasingDelay added in v1.6.0

func GetIncreasingDelay(minDuration time.Duration, maxDuration time.Duration) IncreasingDelay

Returns a increasing duration to have less polling overhead but keep a higher frequency in the first day

given: min: 2, max: 9 Timeline: start max now Result: 22223333444455556666777788889999999999999999999

func (IncreasingDelay) GetNextDelay added in v1.6.0

func (d IncreasingDelay) GetNextDelay() time.Duration

type Parameters

type Parameters map[string]string

type ServerContext added in v1.6.3

type ServerContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewServerContext added in v1.6.3

func NewServerContext() *ServerContext

wrapper for ctx to simply add childs which have a blocking shutdown process -> make sure all stuff is closed properly before exit todo directly add term/kill handling

func (*ServerContext) ChildDone added in v1.6.3

func (c *ServerContext) ChildDone()

...mark a child shutdown as done (-> use this method in defer)

func (*ServerContext) RegisterChild added in v1.6.3

func (c *ServerContext) RegisterChild()

add a new child...

func (*ServerContext) StopTheWorld added in v1.6.3

func (c *ServerContext) StopTheWorld()

start the shutdown process

type TemplateFunctionProvider

type TemplateFunctionProvider interface {
	GetTemplateFunction() template.FuncMap
}

Jump to

Keyboard shortcuts

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