github.com/argoproj/argo-events@v1.9.1/pkg/apis/common/resource.go (about)

     1  package common
     2  
     3  import "encoding/json"
     4  
     5  /**
     6  This inspired by intstr.IntOrStr and json.RawMessage.
     7  */
     8  
     9  // Resource represent arbitrary structured data.
    10  type Resource struct {
    11  	Value []byte `json:"value" protobuf:"bytes,1,opt,name=value"`
    12  }
    13  
    14  func NewResource(s interface{}) Resource {
    15  	data, _ := json.Marshal(s)
    16  	return Resource{Value: data}
    17  }
    18  
    19  func (a *Resource) UnmarshalJSON(value []byte) error {
    20  	a.Value = value
    21  	return nil
    22  }
    23  
    24  func (n Resource) MarshalJSON() ([]byte, error) {
    25  	return n.Value, nil
    26  }
    27  
    28  func (n Resource) OpenAPISchemaType() []string {
    29  	return []string{"object"}
    30  }
    31  
    32  func (n Resource) OpenAPISchemaFormat() string { return "" }