Documentation ¶
Index ¶
- func Create(configPath string, name string) (*Application, Error)
- func CreateWithBuilder(configPath string, name string, builderFn ConfigurationBuilderFn) (*Application, Error)
- func LoadProfile(defaultProfile Profile) error
- func NewConfiguration(path string) (*Configuration, Error)
- func NewConfigurationFromContents(contents string) (*Configuration, Error)
- func OverrideProfile(p Profile)
- func OverrideProfileValue(value *string) error
- type Application
- type CLIArgs
- type Configuration
- func (c *Configuration) GetBoolValue(fieldName string) (*bool, Error)
- func (c *Configuration) GetFloatValue(fieldName string) (*float64, Error)
- func (c *Configuration) GetIntValue(fieldName string) (*int, Error)
- func (c *Configuration) GetStringValue(fieldName string) (*string, Error)
- func (c *Configuration) GetUintValue(fieldName string) (*uint, Error)
- func (c *Configuration) GetValueMetadata(fieldName string) *ValueMetadata
- func (c *Configuration) LoadFields(cliArgs []string) Error
- type ConfigurationBuilderFn
- type Error
- func NewAlreadyExistsError(format string, args ...any) Error
- func NewIOError(format string, args ...any) Error
- func NewIllegalArgumentError(format string, args ...any) Error
- func NewIllegalStateError(format string, args ...any) Error
- func NewInternalError(format string, args ...any) Error
- func NewNotFoundError(format string, args ...any) Error
- func NewSvcUnavailableError(format string, args ...any) Error
- func NewSysConfigError(format string, args ...any) Error
- func NewValidationError(format string, args ...any) Error
- type ErrorBuilder
- func BuildAlreadyExistsError() *ErrorBuilder
- func BuildIOError() *ErrorBuilder
- func BuildIllegalArgumentError() *ErrorBuilder
- func BuildIllegalStateError() *ErrorBuilder
- func BuildInternalError() *ErrorBuilder
- func BuildNotFoundError() *ErrorBuilder
- func BuildSvcUnavailableError() *ErrorBuilder
- func BuildSysConfigError() *ErrorBuilder
- func BuildValidationError() *ErrorBuilder
- func NewErrorBuilder(code ErrorCode, codeValue string) *ErrorBuilder
- func NewErrorBuilderWithFactory(code ErrorCode, codeValue string, fn func(impl *ErrorImpl) Error) *ErrorBuilder
- type ErrorCode
- type ErrorImpl
- func (e *ErrorImpl) Cause() error
- func (e *ErrorImpl) Code() ErrorCode
- func (e *ErrorImpl) CodeValue() string
- func (e *ErrorImpl) Error() string
- func (e *ErrorImpl) GetContext() string
- func (e *ErrorImpl) GetMetadata() map[string]string
- func (e *ErrorImpl) GetMetadataValue(key string) string
- func (e *ErrorImpl) SetContext(ctx string)
- type Field
- type FieldBuilder
- func (b *FieldBuilder[T]) ArgName(argName string) *FieldBuilder[T]
- func (b *FieldBuilder[T]) ConfigName(configSectionName string, configFieldName string) *FieldBuilder[T]
- func (b *FieldBuilder[T]) Default(defaultValue T) *FieldBuilder[T]
- func (b *FieldBuilder[T]) Descriptions(shortDesc string, longDesc string) *FieldBuilder[T]
- func (b *FieldBuilder[T]) EnvVar(envVar string) *FieldBuilder[T]
- func (b *FieldBuilder[T]) Register() *Field
- func (b *FieldBuilder[T]) Required() *FieldBuilder[T]
- func (b *FieldBuilder[T]) ShortDesc(shortDesc string) *FieldBuilder[T]
- type FieldRegistry
- func (r *FieldRegistry) CreateBooleanField(name string) *FieldBuilder[bool]
- func (r *FieldRegistry) CreateFloatField(name string) *FieldBuilder[float64]
- func (r *FieldRegistry) CreateIntField(name string) *FieldBuilder[int]
- func (r *FieldRegistry) CreateStringField(name string) *FieldBuilder[string]
- func (r *FieldRegistry) CreateUintField(name string) *FieldBuilder[uint]
- type FieldSpecifier
- type FieldType
- type Profile
- type ValueMetadata
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
func Create(configPath string, name string) (*Application, Error)
Create the Application. This should be done after configuration fields are registered
func CreateWithBuilder ¶
func CreateWithBuilder(configPath string, name string, builderFn ConfigurationBuilderFn) (*Application, Error)
CreateWithBuilder creates the Application using the additional ConfigurationBuilderFn to add application specific configuration
func LoadProfile ¶
LoadProfile will attempt to fetch the active profile from the environment. If no active profile is specified then the defaultProfile will be used.
func NewConfiguration ¶
func NewConfiguration(path string) (*Configuration, Error)
NewConfiguration creates a Configuration from the given ini file path
func NewConfigurationFromContents ¶
func NewConfigurationFromContents(contents string) (*Configuration, Error)
NewConfigurationFromContents creates a Configuration from the given ini contents
func OverrideProfile ¶
func OverrideProfile(p Profile)
OverrideProfile allows for active profile to be overridden
func OverrideProfileValue ¶
OverrideProfileValue allows for the active profile to be overridden in out of band cases like unit tests.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
type CLIArgs ¶
type CLIArgs struct {
// contains filtered or unexported fields
}
CLIArgs stores parsed command line args
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration encapsulates the configuration for an application
func (*Configuration) GetBoolValue ¶
func (c *Configuration) GetBoolValue(fieldName string) (*bool, Error)
func (*Configuration) GetFloatValue ¶
func (c *Configuration) GetFloatValue(fieldName string) (*float64, Error)
func (*Configuration) GetIntValue ¶
func (c *Configuration) GetIntValue(fieldName string) (*int, Error)
func (*Configuration) GetStringValue ¶
func (c *Configuration) GetStringValue(fieldName string) (*string, Error)
func (*Configuration) GetUintValue ¶
func (c *Configuration) GetUintValue(fieldName string) (*uint, Error)
func (*Configuration) GetValueMetadata ¶
func (c *Configuration) GetValueMetadata(fieldName string) *ValueMetadata
GetValueMetadata returns the metadata obtained when parsing a Field with the associated fieldName
func (*Configuration) LoadFields ¶
func (c *Configuration) LoadFields(cliArgs []string) Error
LoadFields loads the values from the registered fields into the configuration
type ConfigurationBuilderFn ¶
type ConfigurationBuilderFn func(registry *FieldRegistry) Error
ConfigurationBuilderFn function used by an Application to build its configuration field definitions
type Error ¶
type Error interface { error Code() ErrorCode CodeValue() string Cause() error GetContext() string SetContext(string) GetMetadataValue(string) string GetMetadata() map[string]string }
Error interface describes an application error
func NewAlreadyExistsError ¶
func NewIOError ¶
func NewIllegalArgumentError ¶
func NewIllegalStateError ¶
func NewInternalError ¶
func NewNotFoundError ¶
func NewSvcUnavailableError ¶
func NewSysConfigError ¶
func NewValidationError ¶
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 relates to a client level error where the result of an operation is to produce a new entity but the entity already exists in the system
const IOErrorCode ErrorCode = 9
IOErrorCode relates to an error while trying to access a resource like a file
const IllegalArgumentError ErrorCode = 4
IllegalArgumentError 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 relates to a client level error where an entity is referenced by the client that does not exist
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) Error ¶
Error returns a descriptor string that encapsulates all the error's metadata. This satisfies the 'error' interface
func (*ErrorImpl) GetContext ¶
GetContext returns this error's optional context
func (*ErrorImpl) GetMetadata ¶
GetMetadata returns this error's optional metadata. It can be nil
func (*ErrorImpl) GetMetadataValue ¶
GetMetadataValue returns a value from this error's metadata.
func (*ErrorImpl) SetContext ¶
SetContext identifies the context of this error
type Field ¶
type Field struct { ShortDescription string LongDescription string Name string ArgName string EnvVar string ConfigSectionName string ConfigFieldName string DefaultValue any Required bool Type ValueType }
Field defines a general field for configuration
type FieldBuilder ¶
type FieldBuilder[T FieldType] struct { // contains filtered or unexported fields }
FieldBuilder builder for a Field
func (*FieldBuilder[T]) ArgName ¶
func (b *FieldBuilder[T]) ArgName(argName string) *FieldBuilder[T]
func (*FieldBuilder[T]) ConfigName ¶
func (b *FieldBuilder[T]) ConfigName(configSectionName string, configFieldName string) *FieldBuilder[T]
func (*FieldBuilder[T]) Default ¶
func (b *FieldBuilder[T]) Default(defaultValue T) *FieldBuilder[T]
func (*FieldBuilder[T]) Descriptions ¶
func (b *FieldBuilder[T]) Descriptions(shortDesc string, longDesc string) *FieldBuilder[T]
func (*FieldBuilder[T]) EnvVar ¶
func (b *FieldBuilder[T]) EnvVar(envVar string) *FieldBuilder[T]
func (*FieldBuilder[T]) Register ¶
func (b *FieldBuilder[T]) Register() *Field
func (*FieldBuilder[T]) Required ¶
func (b *FieldBuilder[T]) Required() *FieldBuilder[T]
func (*FieldBuilder[T]) ShortDesc ¶
func (b *FieldBuilder[T]) ShortDesc(shortDesc string) *FieldBuilder[T]
type FieldRegistry ¶
type FieldRegistry struct {
// contains filtered or unexported fields
}
FieldRegistry is used to create and store Fields
func (*FieldRegistry) CreateBooleanField ¶
func (r *FieldRegistry) CreateBooleanField(name string) *FieldBuilder[bool]
CreateBooleanField Builds a new bool type FieldBuilder
func (*FieldRegistry) CreateFloatField ¶
func (r *FieldRegistry) CreateFloatField(name string) *FieldBuilder[float64]
CreateFloatField Builds a new float64 type FieldBuilder
func (*FieldRegistry) CreateIntField ¶
func (r *FieldRegistry) CreateIntField(name string) *FieldBuilder[int]
CreateIntField Builds a new Integer type FieldBuilder
func (*FieldRegistry) CreateStringField ¶
func (r *FieldRegistry) CreateStringField(name string) *FieldBuilder[string]
CreateStringField Builds a new string type FieldBuilder
func (*FieldRegistry) CreateUintField ¶
func (r *FieldRegistry) CreateUintField(name string) *FieldBuilder[uint]
CreateUintField Builds a new uint type FieldBuilder
type FieldSpecifier ¶
type FieldSpecifier uint8
FieldSpecifier is the enumerated source type that was responsible for specifying the Field's value
const ( None FieldSpecifier = iota EnvironmentVar CommandLine File )
type Profile ¶
type Profile uint8
Profile enum
func GetActiveProfile ¶
func GetActiveProfile() Profile
GetActiveProfile returns the Profile that the application is running under
type ValueMetadata ¶
type ValueMetadata struct { Value any Specifier FieldSpecifier Field *Field }
ValueMetadata contains the resolved value of a Field as well as some extraction metadata