util

package
v0.0.0-...-8a38cc6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CTXKeyUser          contextKey = "user"
	CTXKeyAccessToken   contextKey = "access_token"
	CTXKeyRequestID     contextKey = "request_id"
	CTXKeyDisableLogger contextKey = "disable_logger"
	CTXKeyCacheControl  contextKey = "cache_control"
)
View Source
const (
	HTTPHeaderCacheControl = "Cache-Control"
	TokenTypeBearer        = "Bearer"
)

Variables

This section is empty.

Functions

func BindAndValidate

func BindAndValidate(c echo.Context, v runtime.Validatable, vs ...runtime.Validatable) error

BindAndValidate binds the request, parsing path+query+body and validating these structs.

func BindAndValidateBody

func BindAndValidateBody(c echo.Context, v runtime.Validatable) error

BindAndValidateBody binds the request body and performs validation.

func BindAndValidatePathAndQueryParams

func BindAndValidatePathAndQueryParams(c echo.Context, v runtime.Validatable) error

BindAndValidatePathAndQueryParams binds path and query params and performs validation.

func BindAndValidatePathParams

func BindAndValidatePathParams(c echo.Context, v runtime.Validatable) error

BindAndValidatePathParams binds path params and performs validation.

func BindAndValidateQueryParams

func BindAndValidateQueryParams(c echo.Context, v runtime.Validatable) error

BindAndValidateQueryParams binds query params and performs validation.

func ContainsAllString

func ContainsAllString(slice []string, sub ...string) bool

ContainsAllString checks whether the given string slice contains all strings provided.

func ContainsString

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

ContainsString checks whether the given string slice contains the string provided.

func DisableLogger

func DisableLogger(ctx context.Context, shouldDisable bool) context.Context

func GenerateJwt

func GenerateJwt(email string, exp time.Duration) (sql.NullString, error)

func GetEnv

func GetEnv(key string, defaultVal string) string

func GetEnvAsBool

func GetEnvAsBool(key string, defaultVal bool) bool

func GetEnvAsInt

func GetEnvAsInt(key string, defaultVal int) int

func GetEnvAsStringArr

func GetEnvAsStringArr(key string, defaultVal []string, separator ...string) []string

GetEnvAsStringArr reads ENV and returns the values split by separator.

func GetEnvAsStringArrTrimmed

func GetEnvAsStringArrTrimmed(key string, defaultVal []string, separator ...string) []string

GetEnvAsStringArrTrimmed reads ENV and returns the whitespace trimmed values split by separator.

func GetEnvAsURL

func GetEnvAsURL(key string, defaultVal string) *url.URL

func GetEnvAsUint32

func GetEnvAsUint32(key string, defaultVal uint32) uint32

func GetEnvAsUint8

func GetEnvAsUint8(key string, defaultVal uint8) uint8

func GetEnvEnum

func GetEnvEnum(key string, defaultVal string, allowedValues []string) string

func GetProjectRootDir

func GetProjectRootDir() string

GetProjectRootDir returns the path as string to the project_root for a **running application**.

func LogFromContext

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

LogFromContext returns a request-specific zerolog instance using the provided context. The returned logger will have the request ID as well as some other value predefined. If no logger is associated with the context provided, the global zerolog instance will be returned instead - this function will _always_ return a valid (enabled) logger. Should you ever need to force a disabled logger for a context, use `util.DisableLogger(ctx, true)` and pass the context returned to other code/`LogFromContext`.

func LogFromEchoContext

func LogFromEchoContext(c echo.Context) *zerolog.Logger

LogFromEchoContext returns a request-specific zerolog instance using the echo.Context of the request. The returned logger will have the request ID as well as some other value predefined.

func LogLevelFromString

func LogLevelFromString(s string) zerolog.Level

func ParseFileUpload

func ParseFileUpload(c echo.Context, formNameFile string, allowedMIMETypes []string) (*multipart.FileHeader, multipart.File, *mimetype.MIME, error)

ParseFileUpload handles file uploads and validates MIME types.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, error)

func ShouldDisableLogger

func ShouldDisableLogger(ctx context.Context) bool

func UniqueString

func UniqueString(slice []string) []string

UniqueString takes the string slice provided and returns a new slice with all duplicates removed.

func ValidateAndReturn

func ValidateAndReturn(c echo.Context, code int, v runtime.Validatable) error

ValidateAndReturn returns the provided data as a JSON response after performing payload validation.

func VerifyJWT

func VerifyJWT(tokenString string) (jwt.MapClaims, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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