https://github.com/eexit/vresolver
Simple and flexible way to fetch your app version
https://github.com/eexit/vresolver
golang golang-library golang-package golang-tools versioning versions
Last synced: 5 months ago
JSON representation
Simple and flexible way to fetch your app version
- Host: GitHub
- URL: https://github.com/eexit/vresolver
- Owner: eexit
- License: mit
- Created: 2019-06-12T18:41:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-24T15:38:32.000Z (over 6 years ago)
- Last Synced: 2025-08-14T18:55:29.653Z (5 months ago)
- Topics: golang, golang-library, golang-package, golang-tools, versioning, versions
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# V(ersion) Resolver [](https://travis-ci.org/eexit/vresolver) [](https://codecov.io/gh/eexit/vresolver)
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:
- Environment variable
- [AWS ECS Metadata File](https://blog.eexit.net/aws-ecs-seamlessly-handle-app-versioning/)
- Fallback
- Composite
### Example
```go
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
```bash
$ go get -u github.com/eexit/vresolver
```
## Test
```bash
$ go test -v -race ./...
```
## Custom resolver
You can build a custom resolver as long as it matches the following type:
```go
type Resolver func(input string) string
```
For instance, let's create a `Panic` resolver, that panics if no version is resolved:
```go
// 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")
```