gojay

command
v0.0.0-...-aa9e309 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2018 License: MIT Imports: 13 Imported by: 0

README

Gojay code generator

This package provides a command line tool to generate gojay's marshaling and unmarshing interface implementation for struct, slice and map types.

Get started

go install github.com/francoispqt/gojay/gojay

Generate code

Basic command

The basic command is straightforward and easy to use:

gojay github.com/some/package TypeA,TypeB,TypeC output.go 

If you just want to the output to stdout, omit the third parameter.

Using flags
  • p package to parse, relative path to $GOPATH/src
  • s file/dir to path, can be a relative or absolute path
  • t types to generate (comma separated)
  • o output file (relative or absolute path)

Examples:

  • Specific types in a go package, to stdout:
gojay -p github.com/francoispqt/gojay/gojay/tests -t A,B,StrSlice 
  • Specific types in a go package, write to a file:
gojay -p github.com/francoispqt/gojay/gojay/tests -t A,B,StrSlice -o output.go
  • Specific types in a go file, to stdout:
gojay -s somegofile.go -t SomeType

Gojay tags

You can add tags to your structs to control:

  • the JSON key
  • skip a struct field only for unmarshaling
  • skip a struct field only for marshaling
  • skip a struct field
  • the use of omit empty methods for marshaling
Example:
type A struct {
    Str             string  `gojay:"string"`
    StrOmitEmpty    string  `gojay:"string,omitempty"`
    SkipUnmarshal   string  `gojay:"skipUnmarshal,-u"`
    SkipMarshal     string  `gojay:"skipMarshal,-m"`
    Skip            string  `gojay:"-"`
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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