helper

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCacheHeader added in v1.2.0

func AddCacheHeader(header *http.Header, maxAge int)

AddCacheHeader add cache headers

func AddXForwardHeader added in v1.2.0

func AddXForwardHeader(header *http.Header, host string)

AddXForwardHeader add X-Forwarded-For header

func ContainsString added in v1.1.0

func ContainsString(s []string, str string) bool

ContainsString retrn true if the slice contains the string

func ConvGraphQLID

func ConvGraphQLID(id interface{}) *uint

ParseGraphQLID parse GraphQL argument as uint

func CountLines

func CountLines(r io.Reader) (uint, error)

CountLines count lines of a Reader

func GetIntOrDefault

func GetIntOrDefault(values url.Values, key string, defaultValue int) int

GetIntOrDefault return value as int or the default

func Hash

func Hash(values ...string) string

Hash creates a hash from a payload string

func If

func If[T any](cond bool, vtrue, vfalse T) T

If return value regarding the condition

func InvalidParameterError

func InvalidParameterError(name string) error

InvalidParameterError create invalid parameter error

func NewBackgroundContextWithValues

func NewBackgroundContextWithValues(src context.Context) context.Context

NewBackgroundContextWithValues create new context with same values than another context

func NewUTF8Reader

func NewUTF8Reader(reader io.Reader, sourceCharset string) (io.Reader, error)

NewUTF8Reader converts a reader from a charset to UTF-8

func OneIsEmpty

func OneIsEmpty(values ...*string) bool

OneIsEmpty test if one of the pointers is nil or reference an empty string

func OpenResource

func OpenResource(location string) (io.ReadCloser, error)

OpenResource open local or remote resource as a Reader

func ParseGraphQLArgument

func ParseGraphQLArgument[T string | bool | int](args map[string]interface{}, name string) *T

ParseGraphQLArgument parse GraphQL argument

func ParseGraphQLID

func ParseGraphQLID(args map[string]interface{}, name string) *uint

ParseGraphQLID parse GraphQL argument as uint

func PtrValueOr

func PtrValueOr[T any](obj *T, fallback T) T

PtrValueOr return value of the pointer or a fallback if nil

func RequireParameterError

func RequireParameterError(name string) error

RequireParameterError create require parameter error

func ToUTF8

func ToUTF8(iso string) string

ToUTF8 converts ISO string to UTF8

func Truncate

func Truncate(value string, size int) string

Truncate string

func WriteProblemDetail

func WriteProblemDetail(w http.ResponseWriter, title, detail string, status int)

WriteProblemDetail write error as JSON Problem Details format

Types

type FieldsValidator

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

func (*FieldsValidator) Error

func (v *FieldsValidator) Error() error

func (*FieldsValidator) Validate

func (v *FieldsValidator) Validate(name string, isValid func() bool)

type HashIDHandler

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

HashIDHandler is used to hash a string with hashid algorythm

func NewHashIDHandler

func NewHashIDHandler(salt []byte) (*HashIDHandler, error)

NewHashIDHandler creates hashid handler

func (*HashIDHandler) Decode

func (hid *HashIDHandler) Decode(hash string) ([]int, error)

Decode value from hashid

func (*HashIDHandler) Encode

func (hid *HashIDHandler) Encode(values []int) string

Encode values into hashid

type HtpasswdFile

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

HtpasswdFile is a map for usernames to passwords.

func NewHtpasswdFromFile

func NewHtpasswdFromFile(location string) (*HtpasswdFile, error)

newHtpasswdFromFile reads the users and passwords from a htpasswd file and returns them.

func (*HtpasswdFile) Authenticate

func (h *HtpasswdFile) Authenticate(username, password string) bool

Jump to

Keyboard shortcuts

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