uninitialized

command module
v0.0.0-...-c62489d Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 11 Imported by: 0

README

Uninitialized

Uninitialized: check for uninitialized but required struct fields within composite literals.

Why?

I've found myself wanting required fields within structs as sometimes a zero value is either unworkable or impractical. While constructors can help to mitigate this need, constructors can suffer from the same issue--a new field is added to the type being constructed, but one has forgotten to update the constructor too.

Caveats
Install
go get -u github.com/danielmmetz/uninitialized
Use

Annotate struct fields with a tag: required:"true".

Example:

type Foo struct {
    Member Bar `required:"true"`
}

Composite literals of Foo that do not explicitly set the member field Member will then be flagged.

Example:

func main() {
    _ = Foo{}  // `Foo missing required keys: [Member]`
    _ = Foo{Member: Bar{}}  // OK
}
Run
uninitialized: check for uninitialized but required struct fields within composite literals

Usage: uninitialized [-flag] [package]

Example:

uninitialized ./...

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