Repository: google/go-github
File: tools/structfield/testdata/src/no-warnings/main.go (Go)

Code before:
	"time"
)

type JSONFieldName struct {
	GithubThing string  `json:"github_thing"`
	ID          *string `json:"id,omitempty"`
	Strings     *string `json:"strings,omitempty"`
	Ref         *string `json:"$ref,omitempty"`
	Query       string  `json:"q"`
}

type JSONFieldType struct {
	WithoutTag string

	ID                    *string           `json:"id,omitempty"`
	HookAttributes        map[string]string `json:"hook_attributes,omitempty"`
	Inputs                json.RawMessage   `json:"inputs,omitempty"`
	Exception             string            `json:"exception,omitempty"`
	Value                 any               `json:"value,omitempty"`
	SliceOfPointerStructs []*Struct         `json:"slice_of_pointer_structs,omitempty"`

	SliceOfStrings               []string        `json:"slice_of_strings,omitzero"`
	SliceOfPointerInts           []*int          `json:"slice_of_pointer_ints,omitzero"`
	MapOfStringToInt             map[string]int  `json:"map_of_string_to_int,omitzero"`
	MapOfPointerStringToInt      *map[string]int `json:"map_of_pointer_string_to_int,omitzero"`
	StructField                  Struct          `json:"struct_field,omitzero"`
	PointerStructField           *Struct         `json:"pointer_struct_field,omitzero"`
	SliceOfPointerStructsZero    []*Struct       `json:"slice_of_pointer_structs_zero,omitzero"`
	SliceOfNonPointerStructsZero []Struct        `json:"slice_of_non_pointer_structs_zero,omitzero"`

	SliceOfStringsBoth        []string       `json:"slice_of_strings_both,omitzero,omitempty"`
	MapOfStringToIntBoth      map[string]int `json:"map_of_string_to_int_both,omitzero,omitempty"`
	SliceOfPointerStructsBoth []*Struct      `json:"slice_of_pointer_structs_both,omitzero,omitempty"`
	StructFieldBoth           *Struct        `json:"struct_field_both,omitzero,omitempty"`
}

type URLFieldName struct {
	ID    *string `url:"id,omitempty"`
	Query string  `url:"q"`
}

type URLFieldType struct {
	Page      *string    `url:"page,omitempty"`
	PerPage   *int       `url:"per_page,omitempty"`
	Labels    []string   `url:"labels,omitempty,comma"`
	Since     *time.Time `url:"since,omitempty"`
	Fields    []int64    `url:"fields,omitempty,comma"`
	Exception string     `url:"exception,omitempty"`
}

type Struct struct{}

Review comment (suggestion):
I'm having troubles with:

* `*map[...]...`
* `Struct`
* `[]Struct`

I still think these should not be allowed, but instead use:

* `map[...]...`
* `*Struct`
* `[]*Struct`

But maybe I'm just not getting the whole thing?

cc: @stevehipwell - @alexandear - @zyfy29 - please help me make sense of how we should handle `omitzero` in this repo, as I'm really struggling with this one.

Code after:
	"time"
)

type JSONFieldName struct {
	GithubThing string  `json:"github_thing"`
	ID          *string `json:"id,omitempty"`
	Strings     *string `json:"strings,omitempty"`
	Ref         *string `json:"$ref,omitempty"`
	Query       string  `json:"q"`
}

type JSONFieldType struct {
	WithoutTag string

	ID                    *string           `json:"id,omitempty"`
	HookAttributes        map[string]string `json:"hook_attributes,omitempty"`
	Inputs                json.RawMessage   `json:"inputs,omitempty"`
	Exception             string            `json:"exception,omitempty"`
	Value                 any               `json:"value,omitempty"`
	SliceOfPointerStructs []*Struct         `json:"slice_of_pointer_structs,omitempty"`

	SliceOfStrings            []string       `json:"slice_of_strings,omitzero"`
	MapOfStringToInt          map[string]int `json:"map_of_string_to_int,omitzero"`
	PointerStructField        *Struct        `json:"pointer_struct_field,omitzero"`
	SliceOfPointerStructsZero []*Struct      `json:"slice_of_pointer_structs_zero,omitzero"`

	SliceOfStringsBoth        []string       `json:"slice_of_strings_both,omitzero,omitempty"`
	MapOfStringToIntBoth      map[string]int `json:"map_of_string_to_int_both,omitzero,omitempty"`
	SliceOfPointerStructsBoth []*Struct      `json:"slice_of_pointer_structs_both,omitzero,omitempty"`
	StructFieldBoth           *Struct        `json:"struct_field_both,omitzero,omitempty"`
}

type URLFieldName struct {
	ID    *string `url:"id,omitempty"`
	Query string  `url:"q"`
}

type URLFieldType struct {
	Page      *string    `url:"page,omitempty"`
	PerPage   *int       `url:"per_page,omitempty"`
	Labels    []string   `url:"labels,omitempty,comma"`
	Since     *time.Time `url:"since,omitempty"`
	Fields    []int64    `url:"fields,omitempty,comma"`
	Exception string     `url:"exception,omitempty"`
}

type Struct struct{}