https://github.com/romshark/jsonnet-config-demo-go
A Go demo using jsonnet for configuration
https://github.com/romshark/jsonnet-config-demo-go
configuration go golang json jsonnet
Last synced: 6 months ago
JSON representation
A Go demo using jsonnet for configuration
- Host: GitHub
- URL: https://github.com/romshark/jsonnet-config-demo-go
- Owner: romshark
- License: mit
- Archived: true
- Created: 2023-08-30T18:07:00.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-30T18:20:40.000Z (about 2 years ago)
- Last Synced: 2025-02-23T10:42:59.973Z (7 months ago)
- Topics: configuration, go, golang, json, jsonnet
- Language: Go
- Homepage: https://jsonnet.org/
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonnet-config-demo-go
A Go demo using https://jsonnet.org/ for configuration.
Package `config` provides a generic function `MustParse`, that evaluates the given config file using jsonnet and unmarshals the generated JSON into the given configuration struct type with exported fields. [github.com/go-playground/validator](https://github.com/go-playground/validator) struct tags can be used to constraint individual fields.In the provided [example](https://github.com/romshark/jsonnet-config-demo-go/tree/main/cmd/example1), the following jsonnet configuration:
```jsonnet
local AdminName(name='') = 'user_admin_' + name;{
host: 'localhost:8080',
admins: [AdminName(name='Bob'), AdminName(name='Alice')],
}
```Is parsed into:
```go
type Config struct {
Host string `json:"host" validate:"required,hostname_port"`
Admins []string `json:"admins" validate:"required"`
}
```