A simple package that facilitates fetching of configuration from a Spring Cloud Config Server
go get github.com/realbucksavage/spring-config-client-go/v2
import (
"log"
"github.com/realbucksavage/spring-config-client-go/v2"
)
type applicationConfig struct {
Key1 Key1Type `json:"key1" yaml:"key1"`
// ...
}
func main() {
client, err := cloudconfig.NewClient(
"config:8888",
"someapp",
"production",
)
if err != nil {
panic(err)
}
// get a reader to configuration
rdr, err := client.Raw()
// or, decode configuration directly into a struct
var appConfig applicationConfig
err := client.Decode(&appConfig)
}
The client can also be customized with these options
client, err := cloudconfig.NewClient(
server,
application,
profile,
cloudconfig.WithBasicAuth("username", "password"),
)
client, err := cloudconfig.NewClient(
server,
application,
profile,
cloudconfig.WithFormat(cloudconfig.YAMLFormat)),
)
client, err := cloudconfig.NewClient(
server,
application,
profile,
cloudconfig.WithScheme("https"),
)