utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKeys = map[ContextKey]struct{}{
	UserCtxKey:     {},
	RequestBodyKey: {},
	RequestIDKey:   {},
	TimeKey:        {},
	PathKey:        {},
	MethodKey:      {},
}

Functions

func CompareHashPass

func CompareHashPass(hashedPass, pass string) error

func CompareTokenHash

func CompareTokenHash(storedHash, token string) bool

func CopyContext

func CopyContext(ctx context.Context) context.Context

func ElapsedTime

func ElapsedTime(ctx context.Context) (time.Duration, bool)

func GenerateAndSetKeys

func GenerateAndSetKeys()

func GetContextValue

func GetContextValue(ctx context.Context, key ContextKey) (interface{}, bool)

func GetEdDSAKeysFromEnv

func GetEdDSAKeysFromEnv() (ed25519.PrivateKey, ed25519.PublicKey, error)

func GetMethod

func GetMethod(ctx context.Context) (string, bool)

func GetPath

func GetPath(ctx context.Context) (string, bool)

func GetQueryParam

func GetQueryParam[T string | int](r *http.Request, key string, defaultVal T) T

func GetRequestBody

func GetRequestBody(ctx context.Context) any

func GetRequestID

func GetRequestID(ctx context.Context) (string, bool)

func GetUser

func GetUser(ctx context.Context) *models.User

func HashPass

func HashPass(pass string) (string, error)

func HashToken

func HashToken(token string) string

func Ptr

func Ptr[T any](v T) *T

func SetRequestBody

func SetRequestBody(ctx context.Context, body any) context.Context

func SetUser

func SetUser(ctx context.Context, user *models.User) context.Context

Types

type ContextKey

type ContextKey string
const (
	UserCtxKey     ContextKey = "user"
	RequestBodyKey ContextKey = "request-body"
	RequestIDKey   ContextKey = "request-id"
	TimeKey        ContextKey = "time"
	PathKey        ContextKey = "path"
	MethodKey      ContextKey = "method"
)

Jump to

Keyboard shortcuts

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