lib

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("already exists")
	ErrNotFound      = errors.New("not found")
	ErrUnauthorized  = errors.New("unauthorized")
	ErrForbidden     = errors.New("forbidden")
	ErrUnknown       = errors.New("unknown error")
)
View Source
var (
	ErrJsonContentType = errors.New("Content-Type is not application/json")
	ErrJsonHTTPMethod  = errors.New("HTTP method does not have a body")
)
View Source
var (
	ErrSchemaDecode = errors.New("failed to decode values")
)

Functions

func Base32String

func Base32String(p []byte) string

func ConvertStormError

func ConvertStormError(err error) error

func CurrentTime

func CurrentTime(next http.Handler) http.Handler

func DefaultTokenGenerator

func DefaultTokenGenerator() string

func HTTPError

func HTTPError(w http.ResponseWriter, code int)

func JsonRequest

func JsonRequest(r *http.Request, p interface{}) error

func JsonResponse

func JsonResponse(w http.ResponseWriter, ctx context.Context, p interface{})

func Logger

func Logger(logger zerolog.Logger) func(http.Handler) http.Handler

func MustJsonMarshalToBuffer

func MustJsonMarshalToBuffer(t *testing.T, p interface{}) *bytes.Buffer

func NewToken

func NewToken(n int) []byte

func RunCase

func RunCase(t *testing.T, label interface{}, f func(t *testing.T))

func UseBadger

func UseBadger(ctx context.Context) *badger.DB

func UseLogger

func UseLogger(ctx context.Context) *zerolog.Logger

func UseStorm

func UseStorm(ctx context.Context) *storm.DB

func UseTime

func UseTime(ctx context.Context) time.Time

func Validate

func Validate(p interface{}) error

Validate validates an object using the global validator.

func ValidateQuery

func ValidateQuery(p interface{}, v url.Values) error

ValidateQuery decodes and validates an object from query values using the global decoder and validator.

func WithBadger

func WithBadger(ctx context.Context, db *badger.DB) context.Context

func WithDriverTokenGenerator

func WithDriverTokenGenerator(ctx context.Context, gen TokenGenerator) context.Context

func WithStorm

func WithStorm(ctx context.Context, db *storm.DB) context.Context

func WithTime

func WithTime(ctx context.Context, t time.Time) context.Context

Types

type Adaptor

type Adaptor zerolog.Logger

func (Adaptor) Debugf

func (adaptor Adaptor) Debugf(format string, args ...interface{})

func (Adaptor) Errorf

func (adaptor Adaptor) Errorf(format string, args ...interface{})

func (Adaptor) Infof

func (adaptor Adaptor) Infof(format string, args ...interface{})

func (Adaptor) Warningf

func (adaptor Adaptor) Warningf(format string, args ...interface{})

type AppContextKey

type AppContextKey string
const BadgerContextKey AppContextKey = "badger"
const DriverTokenGeneratorContextKey AppContextKey = "driver_token_generator"
const StormContextKey AppContextKey = "storm"
var TimeContextKey AppContextKey = "time"

type CustomValidator

type CustomValidator interface {
	Validate() error
}

type Middleware

type Middleware func(next http.Handler) http.Handler

func Badger

func Badger(db *badger.DB) Middleware

func DriverTokenGenerator

func DriverTokenGenerator(gen TokenGenerator) Middleware

func Storm

func Storm(path string, opts ...func(*storm.Options) error) Middleware

type TokenGenerator

type TokenGenerator func() string

func UseDriverTokenGenerator

func UseDriverTokenGenerator(ctx context.Context) TokenGenerator

type ValidationError

type ValidationError []validator.FieldError

func (ValidationError) Error

func (err ValidationError) Error() string

Jump to

Keyboard shortcuts

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