Skip to content

Utitlities to transform flat key value collections to complex typed Golang structs

License

Notifications You must be signed in to change notification settings

sergioifg94/auto-struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

auto-struct

auto-struct is a simple, lightweight Go library to obtain complex typed values from a flat, key value collection.

Inspired by the .NET Core environment config provider.

Example

Having the following structs:

type innerTestType struct {
	Value2 int64
	Value3 bool
}

type testType struct {
	Value1     string
	InnerValue innerTestType
}

An instance of the testType struct can be retrieved with the following key-value collection, using . as field separator:

Key Value
"testType.Value1" "hello"
"testType.InnerValue.Value2" "12"
"testType.InnerValue.Value3" "true"

Packages

Package Utility
pkg/generic Generic utility to retrieve structs from a key value collection using reflection
pkg/env Utility to retrieve structs from environment variables
pkg/stringmap Utility to retrieve structs from map[string]string

Unit tests

To execute the unit tests

go test -v ./...

TODO

  • Add support for slices
  • Add support for map[string]xxxx
  • Add functionality to write struct to key value collection

About

Utitlities to transform flat key value collections to complex typed Golang structs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages