(Translated by https://www.hiragana.jp/)
GitHub - eexit/vresolver: Simple and flexible way to fetch your app version
Skip to content

Simple and flexible way to fetch your app version

License

Notifications You must be signed in to change notification settings

eexit/vresolver

Repository files navigation

V(ersion) Resolver Build Status codecov

Simple and flexible way to fetch your app version.

Wether your app is a CLI or runs in background and generate logs, it's never been as easy to fetch your app version with this lib.

Supported resolvers:

Example

import "github.com/eexit/vresolver"

// Tries to fetch the version from the runtime ECS container
// and fallbacks to "bulk-version" otherwise
version := vresolver.Compose(
	vresolver.Env,
	vresolver.ECS,
	vresolver.Fallback("bulk-version"),
)(vresolver.ECSMetadataFileEnvVar)

Installation

$ go get -u github.com/eexit/vresolver

Test

$ go test -v -race ./...

Custom resolver

You can build a custom resolver as long as it matches the following type:

type Resolver func(input string) string

For instance, let's create a Panic resolver, that panics if no version is resolved:

// Panic panics when app has no version
func Panic(input string) string {
	if input == "" {
		panic("no app version was resolved")
	}
	return input
}

version := vresolver.Compose(vresolver.Env, Panic)("MY_APP_VERSION")