Skip to content

Commit

Permalink
Reflect review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zoetrope committed Jul 17, 2024
1 parent c505afa commit d83b557
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions api/v1beta1/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,40 @@ import (
)

// Params represents untyped configuration.
// kubebuilder does not support interface{} member directly, so this struct is a workaround.
// +kubebuilder:validation:Type=object
type Params struct {
// Data holds the parameter keys and values.
Data map[string]interface{} `json:"-"`
}

func (c *Params) ToMap() map[string]interface{} {
if c == nil {
// ToMap converts the Params to map[string]interface{}. If the receiver is nil, it returns nil.
func (p *Params) ToMap() map[string]interface{} {
if p == nil {
return nil
}
return c.Data
return p.Data
}

// MarshalJSON implements the Marshaler interface.
func (c *Params) MarshalJSON() ([]byte, error) {
return json.Marshal(c.Data)
func (p *Params) MarshalJSON() ([]byte, error) {
return json.Marshal(p.Data)
}

// UnmarshalJSON implements the Unmarshaler interface.
func (c *Params) UnmarshalJSON(data []byte) error {
func (p *Params) UnmarshalJSON(data []byte) error {
var out map[string]interface{}
err := json.Unmarshal(data, &out)
if err != nil {
return err
}
c.Data = out
p.Data = out
return nil
}

// DeepCopyInto is a deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (c *Params) DeepCopyInto(out *Params) {
bytes, err := json.Marshal(c.Data)
// DeepCopyInto is a deep copy function, copying the receiver, writing into `out`. `p` must be non-nil.
func (p *Params) DeepCopyInto(out *Params) {
bytes, err := json.Marshal(p.Data)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit d83b557

Please sign in to comment.