musttag

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 11 Imported by: 0

README ยถ

musttag

ci docs report codecov

A Go linter that enforces field tags in (un)marshaled structs

๐Ÿ“Œ About

musttag checks if struct fields used in Marshal/Unmarshal are annotated with the relevant tag:

// BAD:
var user struct {
	Name string
}
data, err := json.Marshal(user)

// GOOD:
var user struct {
	Name string `json:"name"`
}
data, err := json.Marshal(user)

The rational from Uber Style Guide:

The serialized form of the structure is a contract between different systems. Changes to the structure of the serialized form, including field names, break this contract. Specifying field names inside tags makes the contract explicit, and it guards against accidentally breaking the contract by refactoring or renaming fields.

๐Ÿš€ Features

  • encoding/json support
  • encoding/xml support
  • gopkg.in/yaml.v3 support
  • github.com/BurntSushi/toml support
  • github.com/mitchellh/mapstructure support

๐Ÿ“ฆ Install

go install github.com/junk1tm/musttag/cmd/musttag

๐Ÿ“‹ Usage

musttag ./...

With go vet:

go vet -vettool=$(which musttag) ./...

๐Ÿ“… Roadmap

  • Support custom tags via config

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "musttag",
	Doc:      "check if struct fields used in Marshal/Unmarshal are annotated with the relevant tag",
	Requires: []*analysis.Analyzer{inspectpass.Analyzer},
	Run:      run,
}

Functions ยถ

This section is empty.

Types ยถ

This section is empty.

Directories ยถ

Path Synopsis
cmd
musttag command

Jump to

Keyboard shortcuts

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