gojay

command
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gojay code generator

This package provides a command line tool to generate gojay's marshaling and unmarshaling interface implementation for custom struct type(s)

Get started

go install github.com/francoispqt/gojay/gojay

Generate code

Basic command

The basic command is straightforward and easy to use:

cd $GOPATH/src/github.com/user/project
gojay -s . -p true -t MyType -o output.go

If you just want to the output to stdout, omit the -o flag.

Using flags
  • s Source file/dir path, can be a relative or absolute path
  • t Types to generate with all its dependencies (comma separated)
  • a Annotation tag used to read metadata (default: json)
  • o Output file (relative or absolute path)
  • p Pool to reuse object (using sync.Pool)

Examples:

  • Generate SomeType type in /tmp/myproj go package, write to file output.go:
gojay -s /tmp/myproj -t SomeType -o output.go
  • Generate type SomeType in file somegofile.go, with custom tag gojay, write to stdout:
gojay -s somegofile.go -a gojay -t SomeType

Generator tags

You can add tags to your structs to control:

  • the JSON key
  • skip a struct field
  • the use of omitempty methods for marshaling
  • timeFormat (java style data format)
  • timeLayout (golang time layout)
Example:
type A struct {
	Str          string     `json:"string"`
	StrOmitEmpty string     `json:"stringOrEmpty,omitempty"`
	Skip         string     `json:"-"`
	StartTime    time.Time  `json:"startDate" timeFormat:"yyyy-MM-dd HH:mm:ss"`
	EndTime      *time.Time `json:"endDate" timeLayout:"2006-01-02 15:04:05"`
}

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