core

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 4 Imported by: 0

README

go-app-core

A set of utilities to assist/enhance go application development

  • logging with slog
  • errors with metadata
  • configuration profiles (to load profile specific configuration)
  • command line parser
  • toml support
  • string interpolation support
  • Configuration overrides dictated by profile values
  • Configuration struct
  • auditing support (figure out where each file came from)

Documentation

Index

Constants

View Source
const AlreadyExistsErrorCodeValue string = "already-exists"
View Source
const IOErrorCodeValue string = "io"
View Source
const IllegalArgumentErrorCodeValue string = "illegal-argument"
View Source
const IllegalStateErrorCodeValue string = "illegal-state"
View Source
const InternalErrorCodeValue string = "internal"
View Source
const NotFoundErrorCodeValue string = "not-found"
View Source
const ServiceUnavailableErrorCodeValue string = "service-unavailable"
View Source
const SystemConfigurationErrorCodeValue string = "system-configuration"
View Source
const ValidationErrorCodeValue string = "validation"

Variables

This section is empty.

Functions

func GetMapValues

func GetMapValues[K comparable, V comparable](m map[K]V) []V

GetMapValues returns a slice of the specified maps values

func IsWithinRange

func IsWithinRange(v1 any, v2 any, rangeVal float64) bool

IsWithinRange returns true if the two values fall within the given rangeVal

func Normalize

func Normalize(value string) string

Normalize will convert the given string to lower case and trim any leading and trailing whitespace.

func ToFloat64

func ToFloat64(value any) *float64

ToFloat64 casts the given value to a float64 and returns a pointer to it. If the value is not numeric then nil is returned

Types

type CompositeFileConfig

type CompositeFileConfig struct {
}

CompositeFileConfig a file configuration that delegates to a list of file configurations, and returns the first match

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

func NewConfiguration

func NewConfiguration() *Configuration

type Error

type Error interface {
	error
	Code() ErrorCode
	CodeValue() string
	Cause() error
	Context() string
	SetContext(string)
	MetadataValue(string) string
	Metadata() map[string]string
}

Error interface describes an application error

func NewAlreadyExistsError

func NewAlreadyExistsError(format string, args ...any) Error

func NewIOError

func NewIOError(format string, args ...any) Error

func NewIllegalArgumentError

func NewIllegalArgumentError(format string, args ...any) Error

func NewIllegalStateError

func NewIllegalStateError(format string, args ...any) Error

func NewInternalError

func NewInternalError(format string, args ...any) Error

func NewNotFoundError

func NewNotFoundError(format string, args ...any) Error

func NewSvcUnavailableError

func NewSvcUnavailableError(format string, args ...any) Error

func NewSysConfigError

func NewSysConfigError(format string, args ...any) Error

func NewValidationError

func NewValidationError(format string, args ...any) Error

type ErrorBuilder

type ErrorBuilder struct {
	// contains filtered or unexported fields
}

ErrorBuilder builds an Error

func BuildAlreadyExistsError

func BuildAlreadyExistsError() *ErrorBuilder

func BuildIOError

func BuildIOError() *ErrorBuilder

func BuildIllegalArgumentError

func BuildIllegalArgumentError() *ErrorBuilder

func BuildIllegalStateError

func BuildIllegalStateError() *ErrorBuilder

func BuildInternalError

func BuildInternalError() *ErrorBuilder

func BuildNotFoundError

func BuildNotFoundError() *ErrorBuilder

func BuildSvcUnavailableError

func BuildSvcUnavailableError() *ErrorBuilder

func BuildSysConfigError

func BuildSysConfigError() *ErrorBuilder

func BuildValidationError

func BuildValidationError() *ErrorBuilder

func NewErrorBuilder

func NewErrorBuilder(code ErrorCode, codeValue string) *ErrorBuilder

NewErrorBuilder creates a new ErrorBuilder

func NewErrorBuilderWithFactory

func NewErrorBuilderWithFactory(code ErrorCode, codeValue string,
	fn func(impl *ErrorImpl) Error) *ErrorBuilder

NewErrorBuilderWithFactory creates a new ErrorBuilder

func (*ErrorBuilder) Cause

func (b *ErrorBuilder) Cause(err error) *ErrorBuilder

Cause sets the optional error that caused this error

func (*ErrorBuilder) Context

func (b *ErrorBuilder) Context(context string) *ErrorBuilder

Context sets a contextual string that defines the operation in-process when the error occurred

func (*ErrorBuilder) Msg

func (b *ErrorBuilder) Msg(msg string) Error

Msg sets the message for the Error and creates it

func (*ErrorBuilder) Msgf

func (b *ErrorBuilder) Msgf(format string, args ...any) Error

Msgf sets the message for the Error using message formatting and creates it

func (*ErrorBuilder) Str

func (b *ErrorBuilder) Str(key string, val string) *ErrorBuilder

Str sets a string key and value to the metadata associated with this error

type ErrorCode

type ErrorCode uint8
const AlreadyExistsErrorCode ErrorCode = 8

AlreadyExistsErrorCode related to an operation that tries to create an entity that already exists in the system

const IOErrorCode ErrorCode = 9

IOErrorCode relates to an error while trying to interface with a stream of bytes

const IllegalArgumentErrorCode ErrorCode = 4

IllegalArgumentErrorCode relates to an internal server error that means an internal argument check failed. This type of error usually signifies a bug in the software

const IllegalStateErrorCode ErrorCode = 6

IllegalStateErrorCode relates to a client level error that signifies the operation asked of the server cannot be performed because it is not in the proper state

const InternalErrorCode ErrorCode = 1

InternalErrorCode relates to a general internal server error that should be avoided if a more specific one can be chosen

const NotFoundErrorCode ErrorCode = 7

NotFoundErrorCode related to an error where a referenced resource does not exist

const ServiceUnavailableErrorCode ErrorCode = 3

ServiceUnavailableErrorCode signifies that either the server or one of its dependencies is not able to service the request.

const SystemConfigurationErrorCode ErrorCode = 2

SystemConfigurationErrorCode signifies a server error that keeps the server from starting. It is related to an issue that can be fixed in the software's configuration

const UnknownErrorCode ErrorCode = 0
const ValidationErrorCode ErrorCode = 5

ValidationErrorCode signifies a client level error that means the data provided by the client to the server is invalid

type ErrorImpl

type ErrorImpl struct {
	// contains filtered or unexported fields
}

ErrorImpl implements an Error

func (*ErrorImpl) Cause

func (e *ErrorImpl) Cause() error

Cause returns the optional underlying error

func (*ErrorImpl) Code

func (e *ErrorImpl) Code() ErrorCode

Code returns the associated error code

func (*ErrorImpl) CodeValue

func (e *ErrorImpl) CodeValue() string

CodeValue returns the associated error code

func (*ErrorImpl) Context

func (e *ErrorImpl) Context() string

Context returns this error's optional context

func (*ErrorImpl) Error

func (e *ErrorImpl) Error() string

Error returns a descriptor string that encapsulates all the error's metadata. This satisfies the 'error' interface

func (*ErrorImpl) Metadata

func (e *ErrorImpl) Metadata() map[string]string

Metadata returns this error's optional metadata. It can be nil

func (*ErrorImpl) MetadataValue

func (e *ErrorImpl) MetadataValue(key string) string

MetadataValue returns a value from this error's metadata.

func (*ErrorImpl) SetContext

func (e *ErrorImpl) SetContext(ctx string)

SetContext identifies the context of this error

type FileConfig

type FileConfig interface {
	Value() (*string, error)
	IntValue() (*int, error)
	FloatValue() (*float32, error)
	BoolValue() (*bool, error)
}

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Triple

type Triple[T, U, V any] struct {
	First  T
	Second U
	Third  V
}

type Tuple

type Tuple[T, U any] struct {
	First  T
	Second U
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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