cloudconfig

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2022 License: MIT Imports: 7 Imported by: 0

README

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"),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {

	// Raw returns an io.ReadCloser of raw config loaded from server
	Raw() (io.ReadCloser, error)

	// Decode reads the configuration from server, and decodes it into a struct.
	Decode(v interface{}) error
}

Client facilitates connection to the spring config server. The config URL is formed like this: http(s)://{ServerAddr}{/Branch}/{Application}{-Profile}.{json|yaml}

func NewClient

func NewClient(server, application, profile string, opts ...ClientOption) (Client, error)

type ClientOption

type ClientOption func(c *defaultClient) error

func WithBasicAuth

func WithBasicAuth(username, password string) ClientOption

func WithBranch

func WithBranch(branch string) ClientOption

func WithFormat

func WithFormat(format Format) ClientOption

func WithScheme

func WithScheme(scheme string) ClientOption

type Format

type Format string
var (
	JSONFormat Format = "json"
	YAMLFormat Format = "yaml"
)

func (Format) Valid

func (f Format) Valid() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL