Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/score-spec/score-go
Reference library for parsing and loading Score files
https://github.com/score-spec/score-go
go score
Last synced: 3 months ago
JSON representation
Reference library for parsing and loading Score files
- Host: GitHub
- URL: https://github.com/score-spec/score-go
- Owner: score-spec
- License: apache-2.0
- Created: 2022-10-16T23:06:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-01T13:22:22.000Z (3 months ago)
- Last Synced: 2024-11-01T13:25:50.496Z (3 months ago)
- Topics: go, score
- Language: Go
- Homepage:
- Size: 142 KB
- Stars: 26
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# score-go
Reference library containing common types and functions for building Score implementations in Go.
This can be added to your project via:
```sh
go get -u github.com/score-spec/score-go@latest
```**NOTE**: if you project is still using the hand-written types, you will need to stay on `github.com/score-spec/[email protected]`
and any important fixes to the schema may be back-ported to that branch.## Packages
- `github.com/score-spec/score-go/schema` - Go constant with the json schema, and methods for validating a json or yaml structure against the schema.
- `github.com/score-spec/score-go/types` - Go types for Score workloads, services, and resources generated from the json schema.
- `github.com/score-spec/score-go/loader` - Go functions for loading the validated json or yaml structure into a workload struct.
- `github.com/score-spec/score-go/framework` - Common types and functions for Score implementations.## Parsing SCORE files
This library includes a few utility methods to parse source SCORE files.
```go
import (
"os""gopkg.in/yaml.v3"
scoreloader "github.com/score-spec/score-go/loader"
scoreschema "github.com/score-spec/score-go/schema"
scoretypes "github.com/score-spec/score-go/types"
)func main() {
src, err := os.Open("score.yaml")
if err != nil {
panic(err)
}
defer src.Close()var srcMap map[string]interface{}
if err := yaml.NewDecoder(src).Decode(&srcMap); err != nil {
panic(err)
}
if err := scoreschema.Validate(srcMap); err != nil {
panic(err)
}var spec scoretypes.Workload
if err := scoreloader.MapSpec(&spec, srcMap); err != nil {
panic(err)
}
if err := scoreloader.Normalize(&spec, "."); err != nil {
panic(err)
}// Do something with the spec
// ...
}
```## Building a Score implementation
[score-compose](https://github.com/score-spec/score-compose) is the reference Score implementation written in Go and using this library. If you'd like to write a custom Score implementation, use the functions in this library and the `score-compose` implementation as a Guide.
## Upgrading the schema version
When the Score JSON schema is updated in , this repo should be updated to match.
First copy the new `score-v1b1.json` and `samples/` files from the spec repo, into [schema/files](schema/files).
Then regenerate the defined types:
```sh
make generate
```And ensure the tests still pass:
```sh
go test -v ./...
```