utils

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSlugPath = errors.New("Invalid slug path")

ErrInvalidSlugPath indicates an invalid slug path

Functions

func GenerateSecureRandBase64 added in v0.11.0

func GenerateSecureRandBase64(numBytes int) (string, error)

GenerateSecureRandBase64 generates a cryptographically secure random number of the given size and encodes it in a base64 string.

func IsValidSlugPath added in v0.11.0

func IsValidSlugPath(path string) bool

IsValidSlugPath checks that the path is valid, which means it must have both a beginning and trailing slash. The path must no empty parts (i.e. "//").

func MakeProjectionFromKeys

func MakeProjectionFromKeys(validKeys BSONKeySet, keys ...[]string) (bson.M, error)

MakeProjectionFromKeys creates a projection document based on the given keys, optionally performing validation.

func SlugPathDepth added in v0.11.0

func SlugPathDepth(slugPath string) int

SlugPathDepth returns the depth of the given slug path, which is the number of '/' separators in the path, ignoring the trailing slash

func SlugifyPath

func SlugifyPath(path ...string) string

SlugifyPath converts the given path into a safe path with slug tokens. All slug paths begin and end with trailing slash.

func SlugifyPathLower

func SlugifyPathLower(path ...string) string

SlugifyPathLower converts the given path into a safe path with lower-case slug tokens

func SlugifyToken

func SlugifyToken(token string) string

SlugifyToken converts the given token into a safe slug string

func SlugifyTokenLower

func SlugifyTokenLower(token string) string

SlugifyTokenLower converts the given token into a safe, lower-case slug string

func WrapAsTransaction added in v0.10.0

func WrapAsTransaction(ctx context.Context, mdb *mongo.Database, l *log.Entry, transactionCb func(ctx mongo.SessionContext) (interface{}, error)) (interface{}, bool, error)

WrapAsTransaction creates or reuses an existing transaction session. Returns transaction-ret-val, completed, error; where completed is a booleal indicating if the transaction is done (i.e. this is not part of a bigger transaction)

Types

type BSONKeySet

type BSONKeySet map[string]bool

BSONKeySet holds a set of valid BSON keys

func CombineBSONKeys

func CombineBSONKeys(allKeys ...BSONKeySet) BSONKeySet

CombineBSONKeys combines multiple BSONKeySets together. They must not have the same keys.

func ExtractBSONKeys

func ExtractBSONKeys(v interface{}) BSONKeySet

ExtractBSONKeys returns a map of all the BSON keys tagged on the given type

func PrefixBSONKeys

func PrefixBSONKeys(keys BSONKeySet, prefix string) BSONKeySet

PrefixBSONKeys adds the given prefix to all keys in the set

Jump to

Keyboard shortcuts

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