util

package
v0.0.0-...-7beee2d Latest Latest
Warning

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

Go to latest
Published: May 4, 2017 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailOnPanic

func FailOnPanic(t *testing.T)

FailOnPanic can be used in tests in order to recover from a panic and make a test fail.

func MakeEmailTemplate

func MakeEmailTemplate(fileName string, content interface{}) *bytes.Buffer

MakeEmailTemplate parses a given template into the main email layout template, applies the parsed template to the specified content object and returns the result as a bytes.Buffer.

func RandomToken

func RandomToken() string

RandomToken returns a cryptographically strong random token string. The Token is generated from 512 random bits and encoded via base32.StdEncoding

func ReadFormIntoStruct

func ReadFormIntoStruct(request *http.Request, dest interface{}, ignoreMissing bool) error

ReadFormIntoStruct call ParseForm on the request and reads all form data into a struct with matching fields.

See ReadMapIntoStruct for more information.

func ReadMapIntoStruct

func ReadMapIntoStruct(src map[string][]string, dest interface{}, ignoreMissing bool) error

ReadMapIntoStruct reads values from a map of string slices into a struct with matching fields and converts/parses it as needed. ReadMapIntoStruct tries to find matching fields using the original field name or the original name converted into its snake case equivalent.

Supported field types for the target struct are integers, floats, boolean and slices of strings. But the reader does not check whether a string representation of an int, or float actually fits into the destination field.

On errors the reader returns a ValidationError.

func ReadQueryIntoStruct

func ReadQueryIntoStruct(request *http.Request, dest interface{}, ignoreMissing bool) error

ReadQueryIntoStruct reads request query parameters into a struct with matching fields. Single query values are interpreted as coma separated list of values.

See ReadMapIntoStruct for more information.

func RecoveryHandler

func RecoveryHandler(h http.Handler, l interface{}, ps bool) http.Handler

RecoveryHandler recovers from a panic, writes an HTTP InternalServerError, logs the panic message to the defined logging mechanism and continues to the next handler.

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase turns a CamelCase string into its snake_case equivalent.

Types

type EmailDispatcher

type EmailDispatcher interface {
	Send(recipient []string, message []byte) error
}

EmailDispatcher defines an interface for e-mail dispatch.

func NewEmailDispatcher

func NewEmailDispatcher() EmailDispatcher

NewEmailDispatcher returns an instance of emailDispatcher. Dependent on the value of config.smtp.Mode the send method will print the e-mail content to the commandline (value "print"), do nothing (value "skip") or by default send an e-mail via smtp.SendMail.

type StringSet

type StringSet map[string]bool

StringSet is a simple set implementation based on map.

func NewStringSet

func NewStringSet(strs ...string) StringSet

NewStringSet creates a new StringSet from a slice of strings.

func (StringSet) Add

func (set StringSet) Add(s string) StringSet

Add returns a set with one additional element.

func (StringSet) Contains

func (set StringSet) Contains(s string) bool

Contains returns true if a string is part of the set.

func (StringSet) Difference

func (set StringSet) Difference(other StringSet) StringSet

Difference returns a new util.StringSet containing all elements which are not found in the other util.StringSet.

func (StringSet) Intersect

func (set StringSet) Intersect(other StringSet) StringSet

Intersect returns a new set containing only the elements contained in both original sets

func (StringSet) IsSuperset

func (set StringSet) IsSuperset(other StringSet) bool

IsSuperset returns true if the set is a superset of the other set.

func (StringSet) Len

func (set StringSet) Len() int

Len returns the number of elements in the set.

func (*StringSet) Scan

func (set *StringSet) Scan(src interface{}) error

Scan implements the Scanner interface.

func (StringSet) Strings

func (set StringSet) Strings() []string

Strings returns all elements as slice of strings.

func (StringSet) Union

func (set StringSet) Union(other StringSet) StringSet

Union returns a set that contains all elements from both sets.

func (StringSet) Value

func (set StringSet) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ValidationError

type ValidationError struct {
	Message     string
	FieldErrors map[string]string
}

ValidationError provides information about each field of a struct that failed.

func (*ValidationError) Error

func (err *ValidationError) Error() string

Error implements Go error

Jump to

Keyboard shortcuts

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