Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aereal/go-envschema
Validate the runtime environment against given JSON schema.
https://github.com/aereal/go-envschema
go golang json-schema twelve-factor
Last synced: 27 days ago
JSON representation
Validate the runtime environment against given JSON schema.
- Host: GitHub
- URL: https://github.com/aereal/go-envschema
- Owner: aereal
- License: mit
- Created: 2019-01-16T14:52:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-18T09:57:21.000Z (almost 6 years ago)
- Last Synced: 2024-11-30T08:39:27.504Z (28 days ago)
- Topics: go, golang, json-schema, twelve-factor
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/aereal/go-envschema.png?branch=master)][travis]
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
[![GoDoc](https://godoc.org/github.com/aereal/go-envschema?status.svg)][godoc]# go-envschema
Validate the runtime environment against given [JSON schema][json-schema].
## Synopsis
```go
import (
"github.com/aereal/go-envschema/loader"
"github.com/xeipuuv/gojsonschema"
)type config struct {
Addr string `json:"LISTEN_ADDR"`
}func run() error {
// LISTEN_ADDR=localhost:8000loader, err := loader.New(gojsonschema.NewReferenceLoader("file://./config-schema.json"))
if err != nil {
return err
}
cfg := config{}
if err := loader.Load(&cfg); err != nil {
return err
}
// cfg.Addr // => "localhost:8000"return nil
}
```## Motivation
[The Twelve-Factor app][twelve-factor-app] that is container-aware application pattern mainly written by Heroku says the twelve-factor app stores config in environment variables.
That pattern is almost alive to this days but that is lacking in validation system in comparison with common config file pattern.
So all we need is validating the environment variables against the schema and mapping it into runtime structure mechanism.
refs. https://this.aereal.org/entry/container-apps-and-json-schema (Blog entry in Japanese)
## Related works
- [go-playground/validator][go-playground-validator]: focused on validating struct, no environment mapping
[travis]: https://travis-ci.org/aereal/go-envschema
[license]: https://github.com/aereal/go-envschema/blob/master/LICENSE
[godoc]: https://godoc.org/github.com/aereal/go-envschema
[twelve-factor-app]: https://12factor.net
[json-schema]: https://json-schema.org
[go-playground-validator]: https://github.com/go-playground/validator