Skip to content

Make sure your containerized go application fulfills your expected configuration.

License

Notifications You must be signed in to change notification settings

arkadiusjonczek/containerconfig-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

containerconfig-go

Create a go configuration struct from your container configuration environment variables.

Set rules to define if an environment variables is required or optional.

Example

Use the library as shown below:

import (
	"log"
	
	"github.com/arkadiusjonczek/containerconfig-go/configuration"
)

type CustomConfiguration struct {
    RequiredField string
    OptionalField string
}

func main() {
    builder := configuration.NewBuilder[CustomConfiguration]()
    builder.Env("RequiredField")
    builder.Env("OptionalField").SetOptional().WithDefault("optional")
    
    customConfiguration, err := builder.Build()
    if err != nil {
        log.Fatal(err)
    }
    
    log.Println(customConfiguration.RequiredField)
    log.Println(customConfiguration.OptionalField)
}

You can find that example located inside the main directory.

Usage

See the previous example in action:

$ go run main/main.go                    
2024/05/02 08:53:05 environment variable 'RequiredField' is required but was not found
exit status 1
$ RequiredField=Foo go run main/main.go                 
2024/05/02 08:53:20 Foo
2024/05/02 08:53:20 optional
$ RequiredField=Foo OptionalField=Bar go run main/main.go
2024/05/02 08:53:33 Foo
2024/05/02 08:53:33 Bar

About

Make sure your containerized go application fulfills your expected configuration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages