typedjson

command module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 11 Imported by: 0

README

Example

package main

//go:generate typedjson -interface Data *Foo *Bar
type Data interface {
	typedjson(*DataTyped) string
}

type Foo struct {
	Name  string
	Value int
}

type Bar struct {
	Name1   string
	Another []string
}

After generation you will be able to use your Foo and Bar in typed manner:

func main() {
	foo := &Bar{
		Name1: "asd",
	}
	d := DataTyped{}

	d.Data = foo
	b, err := json.MarshalIndent(&d, "", "\t")
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s\n", b)

	d1 := DataTyped{}
	err = json.Unmarshal(b, &d1)
	if err != nil {
		panic(err)
	}
	if !reflect.DeepEqual(d, d1) {
		panic("not equal")
	}

}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL