Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Latest commit

 

History

History
51 lines (39 loc) · 2.28 KB

README.md

File metadata and controls

51 lines (39 loc) · 2.28 KB

casemapper

Functionality was moved into goschtalt v0.21.0 since this is nearly always needed.

Build Status codecov.io Go Report Card GitHub Release GoDoc

An optional set of naming conventions mapping options for goschtalt.

Fairly often we want to use structures for configuration that can't easily be altered. Fortunately goschtalt provides an easy way to inject arbitrary mappers, however that code is fairly boiler plate and clunky to repeat. Hence the value of this library. With the janos/casbab and a bit of glue code, it's now easy to automatically convert to/from config files that may be snake_case into go structures that follow the general conventions.

To set configuration from go structs (AddValue()) or read configuration values from a configuration that is snake_case just use the option in place of goschtalt.KeymapMapper().

	casemapper.ConfigIs("two_words")

With more complex structures there will likely be adjustments will be needed. Adjustments are in the form of a map where keys are the golang struct field name and values are the configuration key name.

For example:

	casemapper.ConfigStoredAs("two_words",
		map[string]string{
            "CfgField": "configuration_field",
			"CNAMEs":   "cnames",
		},
    )

will use the normal snake case mapping except for CfgField and CNAMEs fields, which are mapped to configuration_field and cnames respectively.

References