configmeta

package
v1.20210402.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package configmeta provides a configutil metadata type to provide a cannonical location to hold common config variables.

It provides a couple common variables to set with ldflags on build, namely `configmeta.Version` and `configmeta.GitRef`.

These can be set at build time with `go install -ldflags="-X github.com/blend/go-sdk/configmeta.Version=$(cat ${REPO_ROOT}/VERSION)" project/myapp` as an example.

The typical usage for the configmeta.Meta type is to embed in a config type and resolve it in your resolver.

Config Example:

    type Config struct {
		configmeta.Meta `yaml:",inline"`
	}

	// Resolve resolves the config.
	func (c *Config) Resolve(ctx context.Context) error {
		return configutil.Resolve(ctx,
			(&c.Meta).Resolve,
		)
	}

This will pull `SERVICE_NAME` and `SERVICE_ENV` into relevant fields, as well as `configmeta.Version` into the Version field.

This type is used in a number of other packages for common fields like service name and service environment.

Index

Constants

View Source
const (
	EnvVarProjectConfigPath = "PROJECT_CONFIG_PATH"
	EnvVarConfigPath        = "CONFIG_PATH"
)

EnvVars

View Source
const (
	DefaultConfigFileName = "config.yml"
)

Defaults

Variables

View Source
var (
	// Version is the current version.
	Version = ""
	// GitRef is the currently deployed git ref
	GitRef = "HEAD"
	// ServiceName is the name of the service
	ServiceName = ""
	// ProjectName is the name of the project the service belongs to
	ProjectName = ""
	// Region is the region the service is deployed to
	Region = ""
)

These are set with `-ldflags="-X` on `go install`

Functions

func Paths

func Paths() configutil.Option

Paths returns a configutil option that adds known default config locations.

func PathsFile

func PathsFile(filename string) configutil.Option

PathsFile returns a configutil option that adds known default config locations.

func PathsFileContext

func PathsFileContext(ctx context.Context, filename string) configutil.Option

PathsFileContext returns a configutil option that adds known default config locations.

Types

type Meta

type Meta struct {
	// Region is the aws region the service is deployed to.
	Region string `yaml:"region,omitempty"`
	// ServiceName is name of the service
	ServiceName string `yaml:"serviceName,omitempty"`
	// ProjectName is the project name injected by Deployinator.
	ProjectName string `yaml:"projectName,omitempty"`
	// Environment is the environment of the cluster (sandbox, prod etc.)
	ServiceEnv string `yaml:"serviceEnv,omitempty"`
	// Hostname is the environment of the cluster (sandbox, prod etc.)
	Hostname string `yaml:"hostname,omitempty"`
	// Version is the application version.
	Version string `yaml:"version,omitempty"`
	// GitRef is the git ref of the image.
	GitRef string `yaml:"gitRef,omitempty"`
}

Meta is the cluster config meta.

func (Meta) IsProdlike

func (m Meta) IsProdlike() bool

IsProdlike returns if the cluster meta environment is prodlike.

func (Meta) ProjectNameOrDefault

func (m Meta) ProjectNameOrDefault() string

ProjectNameOrDefault returns the project name or the default.

func (Meta) RegionOrDefault

func (m Meta) RegionOrDefault() string

RegionOrDefault returns the region or the default.

func (*Meta) Resolve

func (m *Meta) Resolve(ctx context.Context) error

Resolve implements configutil.Resolver

func (Meta) ServiceEnvOrDefault

func (m Meta) ServiceEnvOrDefault() string

ServiceEnvOrDefault returns the cluster environment.

func (Meta) ServiceNameOrDefault

func (m Meta) ServiceNameOrDefault() string

ServiceNameOrDefault returns the service name or the default.

func (*Meta) SetFrom

func (m *Meta) SetFrom(other *Meta) configutil.ResolveAction

SetFrom returns a resolve action to set this meta from a root meta.

func (Meta) VersionOrDefault

func (m Meta) VersionOrDefault() string

VersionOrDefault returns a version or a default.

Jump to

Keyboard shortcuts

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