gojsontagstringer

command module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: MIT Imports: 13 Imported by: 0

README

gojsontagstringer

Generates constants for json tags in go structs. Code is based on golang.org/x/tools/cmd/stringer and works similarly.

Manual

Usage of gojsontagstringer:
        gojsontagstringer [flags] -type T [package]
        gojsontagstringer [flags] -type T [directory]
        gojsontagstringer [flags] -type T files... # Must be a single package
For more information, see:
        https://pkg.go.dev/github.com/sgtsquiggs/gojsontagstringer
Flags:
  -output string
        output file name; default srcdir/<type>_string.go
  -tags string
        comma-separated list of build tags to apply
  -type string
        comma-separated list of type names; must be set

Examples

Local Files

Given file car.go:

package car

type Car struct {
	Make  string `json:"make"`
	Model string `json:"model"`
}

Then executing command:

$ gojsontagstringer -type Car car.go

Resulting with file car_jsontags.go:

// Code generated by "gojsontagstringer -type Car car.go"; DO NOT EDIT.

package car

const (
	CarMakeJson  = "make"
	CarModelJson = "model"
)
3rd Party Library

Assumes that the 3rd party package is available to the module in the current working directory.

Executing command:

$ gojsontagstringer -type BoolValue google.golang.org/protobuf/types/known/wrapperspb

Resulting with file boolvalue_jsontags.go:

// Code generated by "gojsontagstringer -type BoolValue google.golang.org/protobuf/types/known/wrapperspb"; DO NOT EDIT.

package local_package

const (
	BoolValueValueJson = "value"
)

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