gonfig

package module
v0.0.0-...-8a800d6 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: BSD-2-Clause Imports: 11 Imported by: 0

README

gonfig

Accessing the Pivotal Cloud Foundry Config Server from Go apps

Simple library which can be used within Go (#golang) microservice applications in order to get the configuration from the PCF Config Server.

All what it does is fetching the access details of the bound PCF Configuration Server from the VCAP environment variables and requests the configuration from the Config Server by using the given credentials.

CI Status

Pivotal's Concourse CI/CD tool also provides badges! For an example pipeline, which compiles and tests the project, see below:

Job Status
Building Build Badge
Testing Test Badge
Push of Example Push Badge

See the complete pipeline for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigChange

func ConfigChange(checkInterval time.Duration) (<-chan Config, error)

ConfigChange checks periodically (checkInterval) if the configuration of the application changed. As soon as there is a difference a new Config object is send into the created Config output channel.

Note that it is not guaranteed to have all updates to the config in the output channel. If for example multiple changes of the configuration occur within one checkInterval then only the latest one will be send out.

func ConfigChangeByLabel

func ConfigChangeByLabel(checkInterval time.Duration, label string) (<-chan Config, error)

ConfigChangeByLabel is the same as ConfigChance with the difference that a label of the configuration can be given (otherwise it would be the master branch configuration).

Types

type Config

type Config map[string]interface{}

Configuration from config server

func FetchConfig

func FetchConfig() (Config, error)

FetchConfig returns the configuration given by the PCF Config Server which is bound as service to the app.

func FetchConfigByLabel

func FetchConfigByLabel(label string) (Config, error)

FetchConfigByLabel returns the configuration from the PCF Config Server for a specifc label. The default label is "master" which is used by FetchConfig(). The label represents for a git configuration typically a branch name.

type ConfigServerResponse

type ConfigServerResponse struct {
	Name     string   `json:"name"`
	Profiles []string `json:"profiles"`
	Label    string   `json:"label"`
	Version  string   `json:"version"`
	// State           interface{} `json:"state"`
	PropertySources []struct {
		// Name is the path to the github repository for example
		Name string `json:"name"`
		// Source contains the actual configuration (float64 for ints)
		Source map[string]interface{} `json:"source"` // Rest of the fields should go here.
	} `json:"propertySources"`
}

ConfigServerResponse encodes is the expected JSON response of the Configuration Server.

type Credentials

type Credentials struct {
	AccessTokenURI string
	ClientID       string
	ClientSecret   string
	URL            URL
}

Credentials are used in order to access the PCF Config Server with oauth2.

func GetConfigServerCredentialsFromEnv

func GetConfigServerCredentialsFromEnv() (*Credentials, error)

GetConfigServerCredentialsFromEnv returns oauth2 and other parameters (app name, space name) out of the PCF environment variables. They are required for accessing the PCF Configuration Server.

func GetServiceCredentialsFromEnv

func GetServiceCredentialsFromEnv(service string) (*Credentials, error)

GetServiceCredentialsFromEnv returns oauth2 and other parameters (app name, space name) out of the PCF environment variables using the given label.

func (*Credentials) GetConfigurationFromServer

func (c *Credentials) GetConfigurationFromServer() (map[string]interface{}, error)

GetConfigurationFromServer requests the current configuration from the Configuration Server using the given Credentials.

type URL

type URL struct {
	URI     string
	App     string
	Profile string
	Label   string
}

URL represents the particles for building the URL to access the configuration from the Pivotal Cloud Foundry configuration server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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