Documentation ¶
Overview ¶
Package configmeta provides a configutil metadata type to provide a canonical 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
- Variables
- func Paths() configutil.Option
- func PathsFile(filename string) configutil.Option
- func PathsFileContext(ctx context.Context, filename string) configutil.Option
- type Meta
- func (m Meta) IsProdlike() bool
- func (m Meta) ProjectNameOrDefault() string
- func (m Meta) RegionOrDefault() string
- func (m *Meta) Resolve(ctx context.Context) error
- func (m Meta) ServiceEnvOrDefault() string
- func (m Meta) ServiceNameOrDefault() string
- func (m *Meta) SetFrom(other *Meta) configutil.ResolveAction
- func (m Meta) VersionOrDefault() string
Constants ¶
const ( EnvVarProjectConfigPath = "PROJECT_CONFIG_PATH" EnvVarConfigPath = "CONFIG_PATH" )
EnvVars
const (
DefaultConfigFileName = "config.yml"
)
Defaults
const (
// DefaultVersion is the version returned if LDFlags have not specified a version.
DefaultVersion = "development"
)
Variables ¶
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 `json:"region,omitempty" yaml:"region,omitempty"` // ServiceName is name of the service ServiceName string `json:"serviceName,omitempty" yaml:"serviceName,omitempty"` // ProjectName is the project name injected by Deployinator. ProjectName string `json:"projectName,omitempty" yaml:"projectName,omitempty"` // Environment is the environment of the cluster (sandbox, prod etc.) ServiceEnv string `json:"serviceEnv,omitempty" yaml:"serviceEnv,omitempty"` // Hostname is the environment of the cluster (sandbox, prod etc.) Hostname string `json:"hostname,omitempty" yaml:"hostname,omitempty"` // Version is the application version. Version string `json:"version,omitempty" yaml:"version,omitempty"` // GitRef is the git ref of the image. GitRef string `json:"gitRef,omitempty" yaml:"gitRef,omitempty"` }
Meta is the cluster config meta.
func (Meta) IsProdlike ¶
IsProdlike returns if the cluster meta environment is prodlike.
func (Meta) ProjectNameOrDefault ¶
ProjectNameOrDefault returns the project name or the default.
func (Meta) RegionOrDefault ¶
RegionOrDefault returns the region or the default.
func (Meta) ServiceEnvOrDefault ¶
ServiceEnvOrDefault returns the cluster environment.
func (Meta) ServiceNameOrDefault ¶
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 ¶
VersionOrDefault returns a version or a default.