Skip to content

Instantly share code, notes, and snippets.

@baijum
Created January 17, 2020 05:18
Show Gist options
  • Select an option

  • Save baijum/e761bc8fb28ba3855e5d1cd118e9192b to your computer and use it in GitHub Desktop.

Select an option

Save baijum/e761bc8fb28ba3855e5d1cd118e9192b to your computer and use it in GitHub Desktop.
JSON struct with inline
package main
import (
"fmt"
"gopkg.in/yaml.v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ApplicationSelector struct {
LabelSelector *metav1.LabelSelector `json:",inline" yaml:",inline"`
Group string `json:"group,omitempty"`
Version string `json:"version"`
Resource string `json:"resource"`
ResourceRef string `json:"resourceRef"`
}
func main() {
as := ApplicationSelector{LabelSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"hi": "ok"}}}
out, _ := yaml.Marshal(as)
fmt.Println(string(out))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment