Skip to content

stucture::optionFromField that cares about capital letters #24

@celian-garcia

Description

@celian-garcia

Hello guy,
Thanks for this work, this is really great.

I have an idea that I'd want to implement in gonfig but I want to have your advice first.

The optionFromField function takes the field name and build the id from it using this code :

	id := f.Tag.Get(fieldTagID)
	if len(id) == 0 {
		id = strings.ToLower(f.Name)
	}
	opt.id = id

Problem is when I have for example the struct field LogLevel, I'd want my config file corresponding field to be log_level.

I can obviously define my struct field like that

type ServerConfiguration struct {
	Port int 		`env:"SERVER_PORT" default:"8080"`
	LogLevel string `id:"log_level" env:"SERVER_LOG_LEVEL" default:"<root>=ERROR"`
}

But I'd prefer to count on a default behaviour.
There I have an issue, what to choose as default behavior :

  • snake case : log_level
  • camel case : logLevel

Maybe we could use as default what you already implemented, but have the possibility to override it in the gonfig.Conf what do you think about it ?

See you !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions