
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?
As documentation of yaml library in Go described, empty structs should be omitted with
omitemptylabel. Link - pkg.go.dev/gopkg.in/yaml.v3Here is the sample prove code for that.
you can run code here