util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SLogger *zap.SugaredLogger
	Logger  *zap.Logger
)

Functions

func DeserializeJson

func DeserializeJson[T any](data []byte) (T, error)

func GetTokenClaims added in v0.5.0

func GetTokenClaims(tokenString string, signingKey string) (map[string]interface{}, error)

func InitLogger

func InitLogger() func(*zap.Logger)

func LoadConfiguration

func LoadConfiguration[T Configuration](configFilePath string, config T) error

LoadConfiguration loads configuration data from a JSON file into the provided 'config' struct. The 'config' struct should implement the 'Configuration' interface. If a 'ValidateJws' method is present on the 'config' struct, it will be called after loading to ensure configuration validity.

Returns an error if there's an issue reading the file, unmarshalling the JSON, or if validation fails.

func LoadEnvironmentVariables

func LoadEnvironmentVariables[T Configuration](config T) error

LoadEnvironmentVariables loads configuration data from environment variables into the provided 'config' struct. The 'config' struct should implement the 'Configuration' interface. struct tags with the "env" key are used to map environment variables to struct fields. If a 'ValidateJws' method is present on the 'config' struct, it will be called after loading to ensure configuration validity.

Returns an error if there's an issue processing environment variables or if validation fails.

func Log

func Log(lvl zapcore.Level, template string, args ...interface{})

func LogError

func LogError(template string, args ...interface{})

func LogInfo

func LogInfo(template string, args ...interface{})

func LogWarn

func LogWarn(template string, args ...interface{})

func NewBearerToken added in v0.5.0

func NewBearerToken(signingKey string) ([]byte, error)

func SerializeJson

func SerializeJson(data interface{}) (string, error)

func ValidateBearerToken added in v0.5.0

func ValidateBearerToken(tokenString string, signingKey string) (bool, error)

Types

type Configuration

type Configuration interface {
	Validate() error
}

Configuration represents a type that can be loaded with configuration data and optionally validated.

Directories

Path Synopsis
jwt
jwe
jws

Jump to

Keyboard shortcuts

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