Skip to content
/ 2go Public

Instantly converts JSON|YAML into a Go type definition in the terminal.

License

Notifications You must be signed in to change notification settings

dlnilsson/2go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2go

Instantly converts JSON|YAML into a Go type definition in the terminal.

Installation

go install github.com/dlnilsson/2go@latest

Example

JSON from stdin

curl -s https://httpbin.org/json | 2go

output

type AutoGenerated struct {
	Slideshow Slideshow `json:"slideshow,omitempty"`
}

type Slides struct {
	Title string `json:"title,omitempty"`
	Type  string `json:"type,omitempty"`
}

type Slideshow struct {
	Author string   `json:"author,omitempty"`
	Date   string   `json:"date,omitempty"`
	Slides []Slides `json:"slides,omitempty"`
	Title  string   `json:"title,omitempty"`
}

YAML from stdin

cat togo/testdata/simple.yaml | 2go
type AutoGenerated struct {
	Kind     string   `yaml:"kind,omitempty"`
	Metadata Metadata `yaml:"metadata,omitempty"`
}

type Metadata struct {
	Name      string `yaml:"name,omitempty"`
	Namespace string `yaml:"namespace,omitempty"`
}

with jq

jq -n --arg favorite "$(echo 'hello world' | base64)" '{fruits: ["apple", "banana", "cherry"], favorite: $favorite}' | 2go

type AutoGenerated struct {
	Favorite []byte   `json:"favorite,omitempty"`
	Fruits   []string `json:"fruits,omitempty"`
}

About

Instantly converts JSON|YAML into a Go type definition in the terminal.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages