generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from cybozu-go/extraparams-any-type
Support for Any Types in ExtraParams
- Loading branch information
Showing
11 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// 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:"-"` | ||
} | ||
|
||
// 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 p.Data | ||
} | ||
|
||
// MarshalJSON implements the Marshaler interface. | ||
func (p *Params) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(p.Data) | ||
} | ||
|
||
// UnmarshalJSON implements the Unmarshaler interface. | ||
func (p *Params) UnmarshalJSON(data []byte) error { | ||
var out map[string]interface{} | ||
err := json.Unmarshal(data, &out) | ||
if err != nil { | ||
return err | ||
} | ||
p.Data = out | ||
return nil | ||
} | ||
|
||
// 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) | ||
} | ||
var clone map[string]interface{} | ||
err = json.Unmarshal(bytes, &clone) | ||
if err != nil { | ||
panic(err) | ||
} | ||
out.Data = clone | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters