utils

package
v0.0.0-...-23b4f48 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInternalServer = errors.New("internal server error")

Functions

func GetEnv

func GetEnv(name string) string

Returns the value of the given environment variable.

Panics if the environment variable isn't set.

func GetOpenFeatureClient

func GetOpenFeatureClient(ctx context.Context, args *GetOpenFeatureClientArgs) *openfeature.Client

Connects to Flagsmith and returns the corresponding Open Feature client.

func MustParseConfig

func MustParseConfig[T any](ctx context.Context, unparsedConfig []byte, validator *validator.Validate) *T

Parses and validates the given unmarshalled config. The parsed config is then returned.

Panics if any error occurs.

func MustParseConfigFile

func MustParseConfigFile[T any](ctx context.Context, configFilePath string, validator *validator.Validate) *T

Parses and validates the config file at the given path. The parsed config is then returned.

Panics if any error occurs.

func NewValidator

func NewValidator(ctx context.Context) *validator.Validate

func RegisterCustomFieldValidators

func RegisterCustomFieldValidators(
	validator *validator.Validate,
	customFieldValidators CustomFieldValidators,
)

func WrapError

func WrapError(err error) error

Returns a new error which contains the stacktrace along with the original error message.

func WrapErrorWithPrefix

func WrapErrorWithPrefix(contextualErrorMessage string, err error) error

Returns a new error which contains :

(1) the stacktrace

(2) some contextual error message along with the original error message.

Types

type APIError

type APIError error

When the presentation layer (in this case, gRPC server) gets :

(1) an error of type APIError, it straight away sends that to the client.
    The gRPC error status code can be decided based on the concrete error type (like
    ErrUserNotFound).

(2) any other type of (unexpected) error, it logs that error and sends the ErrInternalServer back
    to the client.
    The gRPC error status code will always be codes.Internal.

func NewAPIError

func NewAPIError(message string) APIError

Returns an APIError, constructed using the given error message.

type CustomFieldValidators

type CustomFieldValidators = map[string]validator.Func

type GetFlagOrEnvFn

type GetFlagOrEnvFn = func(f *flag.Flag)

func CreateGetFlagOrEnvValueFn

func CreateGetFlagOrEnvValueFn(envPrefix string) GetFlagOrEnvFn

Usage : flagSet.VisitAll(getFlagOrEnvValue("USERS_MICROSERVICE_"))

type GetOpenFeatureClientArgs

type GetOpenFeatureClientArgs struct {
	URL    string `yaml:"url" validate:"required,notblank"`
	APIKey string `yaml:"apiKey" validate:"required,notblank"`

	ClientName string `yaml:"clientName" validate:"required,notblank"`
}

Jump to

Keyboard shortcuts

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