[ANN] extending json tags to variables and enum encoding generator

80 views
Skip to first unread message

Nikolay Dubina

unread,
Mar 27, 2024, 2:28:22 AM3/27/24
to golang-nuts
What?

https://github.com/nikolaydubina/go-enum-encoding

```go
type Color struct{ c uint8 } 

//go:generate go-enum-encoding -type=Color 
var (
    UndefinedColor = Color{}    // json:"-" 
    Red                      = Color{1}  // json:"red" 
    Green                  = Color{2}  // json:"green" 
    Blue                     = Color{3}  // json:"blue"
)
```

This tool extends json tag notation to variables and generates JSON encoding/decoding boilerplate.

More Details

To generate boilerplate JSON encoding/decoding blocks.

This is very lightweight solution of <100 LOC single-file with 100% test coverage. It even generates tests for generated code as well.

I really liked this syntax, so would like to share to others. Cheers!
Reply all
Reply to author
Forward
0 new messages