
type PolicySpec struct {
Description string `json:"description" yaml:"description"`
EndpointSelector Selector `json:"endpointSelector,omitempty" yaml:"ingress,omitempty"`
Severity int `json:"severity,omitempty" yaml:"severity,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Process KubeArmorSys `json:"process,omitempty" yaml:"process,omitempty"`
File KubeArmorSys `json:"file,omitempty" yaml:"network,omitempty"`
Action string `json:"action,omitempty" yaml:"action,omitempty"`
}
I even though added omitempty in the fields yet getting the empty struct in the yaml and json, how to remove those empty structs from the api response body?
nilthey ought to be omitted. At least that's how it works with the encoding/json package, not sure about yaml.encoding/json: "The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string." -- You see? No mention of "empty struct" there.encoding/jsonis concerned, i.e.omitemptyhas no effect on emtpy structs and the package does not honor the "IsZeroer" interface. You'll have to use pointers.