musttag

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 8 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.

Currently musttag supports only the json tag, see Roadmap for future plans.

📦 Install

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

📋 Usage

With go vet:

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

📅 Roadmap

  • Support xml
  • Support yaml
  • Support toml
  • Support mapstructure
  • 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