util

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 11 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

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 GetFullEventKey

func GetFullEventKey(event slack.MessageEvent) string

GetFullEventKey builds a key over user-channel-threadtimestamp

func GetMessageTime

func GetMessageTime(event slack.MessageEvent) time.Time

GetMessageTime will return a time.Time of the sent date from the MessageEvent

func GetShortEventKey

func GetShortEventKey(event slack.MessageEvent) string

GetShortEventKey builds a key over user-channel

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

func RegexpResultToParams

func RegexpResultToParams(regexp *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 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