Categorygithub.com/danielmmetz/uninitialized
modulepackage
0.0.0-20220131024805-c62489d42fb8
Repository: https://github.com/danielmmetz/uninitialized.git
Documentation: pkg.go.dev

# 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 ./...

# Variables

No description provided by the author