Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prasadg193/yaml2go
Converts YAML specs into Go Lang type definitions
https://github.com/prasadg193/yaml2go
convert-yaml-specs go golang yaml yaml-parser yaml-to-go yaml2go yamltogo
Last synced: 3 months ago
JSON representation
Converts YAML specs into Go Lang type definitions
- Host: GitHub
- URL: https://github.com/prasadg193/yaml2go
- Owner: PrasadG193
- License: mit
- Created: 2019-07-19T11:37:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T06:19:09.000Z (over 5 years ago)
- Last Synced: 2024-11-01T02:42:01.488Z (3 months ago)
- Topics: convert-yaml-specs, go, golang, yaml, yaml-parser, yaml-to-go, yaml2go, yamltogo
- Language: Go
- Homepage: https://yaml2go.prasadg.dev
- Size: 245 KB
- Stars: 121
- Watchers: 4
- Forks: 17
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml2go
[![Build Status](https://travis-ci.org/PrasadG193/yaml2go.svg?branch=master)](https://travis-ci.org/PrasadG193/yaml2go)
Converts YAML specs into Go type definitions
![https://github.com/PrasadG193/yaml2go](./yaml2go.png)
## Installation
### Binary Installation
Pre-compiled binaries are available on the releases page. You can download the correct binary depending on your system arch, put it into `$PATH` and hit `yaml2go help`
### Install From Source
Build binary using go build
```bash
$ go get -u github.com/PrasadG193/yaml2go
$ go build -o yaml2go github.com/PrasadG193/yaml2go/cmd/cli
```## Usage
#### Show help
```bash
yaml2go --help
yaml2go converts YAML specs to Go type definitionsUsage:
yaml2go < /path/to/yamlspec.yamlExamples:
yaml2go < test/example1.yaml
yaml2go < test/example1.yaml > example1.go
```#### Convert yaml spec to Go struct
```bash
$ yaml2go < example.yaml
```
e.g```bash
$ cat example1.yaml
kind: test
metadata:
name: cluster
nullfield:
nestedstruct:
- nested:
underscore_field: value
field1:
- 44.5
- 43.6
field2:
- true
- false
nested2:
- nested3:
field1:
- 44
- 43
fieldt:
- true
- false
field3: value
abc:
- def:
- black
- white
array1:
- "string1"
- "string2"
array2:
- 2
- 6
array3:
- 3.14
- 5.12
is_underscore: true
``````bash
$ GOPATH/bin/yaml2go < example1.yaml
// Yaml2Go
type Yaml2Go struct {
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Abc []Abc `yaml:"abc"`
Array1 []string `yaml:"array1"`
Array2 []int `yaml:"array2"`
Array3 []float64 `yaml:"array3"`
IsUnderscore bool `yaml:"is_underscore"`
}// Metadata
type Metadata struct {
Name string `yaml:"name"`
Nullfield interface{} `yaml:"nullfield"`
Nestedstruct []Nestedstruct `yaml:"nestedstruct"`
}// Nested3
type Nested3 struct {
Field1 []int `yaml:"field1"`
Fieldt []bool `yaml:"fieldt"`
Field3 string `yaml:"field3"`
}// Abc
type Abc struct {
Def []string `yaml:"def"`
}// Nestedstruct
type Nestedstruct struct {
Nested Nested `yaml:"nested"`
Nested2 []Nested2 `yaml:"nested2"`
}// Nested
type Nested struct {
UnderscoreField string `yaml:"underscore_field"`
Field1 []float64 `yaml:"field1"`
Field2 []bool `yaml:"field2"`
}// Nested2
type Nested2 struct {
Nested3 Nested3 `yaml:"nested3"`
}
```## Contributing
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features## Credits
The Go Gopher is originally by [Renee French](http://reneefrench.blogspot.com/)This artwork is borrowed from an awesome artwork collection by [Egon Elbre](https://github.com/egonelbre/gophers)