Skip to content

Go client that consumes configuration from a Spring cloud config server

License

Notifications You must be signed in to change notification settings

realbucksavage/spring-config-client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-config-client-go

A simple package that facilitates fetching of configuration from a Spring Cloud Config Server

Installation

go get github.com/realbucksavage/spring-config-client-go/v2

Usage

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

Basic Auth

client, err := cloudconfig.NewClient(
    server, 
    application, 
    profile, 
    cloudconfig.WithBasicAuth("username", "password"),
)

Reading config as YAML instead of (default) JSON

client, err := cloudconfig.NewClient(
    server,
    application,
    profile, 
    cloudconfig.WithFormat(cloudconfig.YAMLFormat)),
)

Using HTTPs (or, setting the scheme of config server's URL)

client, err := cloudconfig.NewClient(
    server,
    application,
    profile, 
    cloudconfig.WithScheme("https"),
)