Skip to content

Commit

Permalink
regen
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasObenaus committed Oct 25, 2024
1 parent a7270af commit e43e1f3
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func getConfigTagDefinition(fieldDeclaration reflect.StructField) (string, bool)
// }
//
// the data map should contain an entry with name 'field_1'
// data := map[string]interface{}{"field_1":"a value"}
//
// data := map[string]interface{}{"field_1":"a value"}
func createAndFillStruct(targetTypeOfStruct reflect.Type, data map[string]interface{}) (reflect.Value, error) {
if targetTypeOfStruct.Kind() != reflect.Struct {
return reflect.Zero(targetTypeOfStruct), fmt.Errorf("The target type must be a struct")
Expand Down
2 changes: 2 additions & 0 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ func registerEnv(vp *viper.Viper, envPrefix string, entry Entry) error {
}

// sliceOfMapStringToInterfaceFlag is a struct that can be used to represent a flag of type
//
// []map[string]interface{}
//
// That is a slice of arbitrary structs.
type sliceOfMapStringToInterfaceFlag struct {
// used to be returned in the String method. Its better to return the value as
Expand Down
3 changes: 3 additions & 0 deletions examples/multilevel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
// ThemeConfig configuration for a theme.
// The different levels are separated by a dot from each another when be set via command line.
// Hence
//
// type ThemeConfig struct {
// Header FormattedTextBox `cfg:"{'name':'header','desc':'The heading'}"`
// }
//
// type FormattedTextBox struct {
// Value string `cfg:"{'name':'value','desc':'The content of the text box','default':''}"`
// }
//
// can be set by
//
// --header.value="hi there"
type ThemeConfig struct {
Header FormattedTextBox `cfg:"{'name':'header','desc':'The heading'}"`
Expand Down
2 changes: 2 additions & 0 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
//
// Just a struct with the desired config parameters has to be defined.
// Each field has to be annotated with the cfg struct tag
//
// `cfg:{'name':'<name of the parameter>','desc':'<description>'}`
//
// The tag has to be specified as json structure using single quotes.
// Mandatory fields are 'name' and 'desc'.
type MyFontConfig struct {
Expand Down
14 changes: 11 additions & 3 deletions extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// configTag represents the definition for a config read from the type tag.
// A config tag on a type is expected to be defined as:
//
// `cfg:"{'name':'<name of the config>','desc':'<description>','default':<default value>,'short':'<shorthand name for the flag>','mapfun':<name of the mapping function>}"`
// `cfg:"{'name':'<name of the config>','desc':'<description>','default':<default value>,'short':'<shorthand name for the flag>','mapfun':<name of the mapping function>}"`
type configTag struct {
Name string `json:"name,omitempty"`
Description string `json:"desc,omitempty"`
Expand All @@ -39,7 +39,9 @@ func (e configTag) HasMapfunc() bool {
}

// parseConfigTagDefinition parses a definition like
// `cfg:"{'name':'<name of the config>','desc':'<description>','default':<default value>,'mapfun':<name of the mapping function>}"`
//
// `cfg:"{'name':'<name of the config>','desc':'<description>','default':<default value>,'mapfun':<name of the mapping function>}"`
//
// to a configTag
func parseConfigTagDefinition(configTagStr string, typeOfEntry reflect.Type, nameOfParent string) (configTag, error) {
configTagStr = strings.TrimSpace(configTagStr)
Expand Down Expand Up @@ -117,15 +119,21 @@ func extractConfigTagFromStructField(field reflect.StructField, parent configTag
// CreateEntriesFromStruct creates Entries based on the annotations provided at the given target struct.
//
// Only fields with annotations of the form
//
// `cfg:"{'name':<name>,'desc':<description>,'default':<default value>}"`
//
// will be regarded.
//
// For example for the struct below
// type Cfg struct {
//
// type Cfg struct {
// Name string `cfg:"{'name':'name','desc':'the name of the config','default':'the name'}"`
// }
//
// A config entry
//
// e := NewEntry("name","the name of the config",Default("the name"))
//
// will be created.
func CreateEntriesFromStruct(target interface{}, logger interfaces.LoggerFunc) ([]Entry, error) {

Expand Down
2 changes: 1 addition & 1 deletion interfaces/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
LogLevelError LogLevel = "Error"
)

//nolint
// nolint
const formatString = "[%s] %s"

// LoggerFunc is a function type that is called whenever the library wants to log a message. This type can be implemented to integrate your custom logging system.
Expand Down
2 changes: 2 additions & 0 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func NewProvider(configEntries []Entry, configName, envPrefix string, options ..
// on the given entries. This config provider automatically generates the needed config entries and fills the given config target
// based on the annotations on this struct.
// In case custom config entries should be used beside the annotations on the struct one can define them via
//
// CustomConfigEntries(customEntries)`
//
// e.g.
//
// customEntries:=[]Entry{
Expand Down

0 comments on commit e43e1f3

Please sign in to comment.