diff --git a/pkg/ami/ami_helper.go b/pkg/ami/ami_helper.go index c579611..4b103e5 100644 --- a/pkg/ami/ami_helper.go +++ b/pkg/ami/ami_helper.go @@ -683,3 +683,35 @@ func JsonString(data interface{}) string { } return string(result) } + +func JsonStringify(data interface{}) string { + s, ok := data.(string) + if ok { + return s + } + result, err := MarshalIndent(data, "", " ") + if err != nil { + return "" + } + return string(result) +} + +func MarshalToString(v interface{}) (string, error) { + return _json.MarshalToString(v) +} + +func MarshalJsonIterator(v interface{}) ([]byte, error) { + return _json.Marshal(v) +} + +func Unmarshal(data []byte, v interface{}) error { + return _json.Unmarshal(data, v) +} + +func UnmarshalFromString(str string, v interface{}) error { + return _json.UnmarshalFromString(str, v) +} + +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + return _json.MarshalIndent(v, prefix, indent) +} diff --git a/pkg/ami/utils/ami_utils.go b/pkg/ami/utils/ami_utils.go deleted file mode 100644 index 6c05e86..0000000 --- a/pkg/ami/utils/ami_utils.go +++ /dev/null @@ -1,60 +0,0 @@ -package utils - -import ( - "log" - - jsonI "github.com/json-iterator/go" -) - -var _json = jsonI.ConfigCompatibleWithStandardLibrary - -func ToJson(data interface{}) string { - s, ok := data.(string) - if ok { - return s - } - // result, err := json.Marshal(data) - result, err := MarshalToString(data) - if err != nil { - log.Printf(err.Error()) - return "" - } - return string(result) -} - -func ToJsonPretty(data interface{}) string { - s, ok := data.(string) - - if ok { - return s - } - - result, err := MarshalIndent(data, "", " ") - - if err != nil { - log.Printf(err.Error()) - return "" - } - - return string(result) -} - -func MarshalToString(v interface{}) (string, error) { - return _json.MarshalToString(v) -} - -func Marshal(v interface{}) ([]byte, error) { - return _json.Marshal(v) -} - -func Unmarshal(data []byte, v interface{}) error { - return _json.Unmarshal(data, v) -} - -func UnmarshalFromString(str string, v interface{}) error { - return _json.UnmarshalFromString(str, v) -} - -func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { - return _json.MarshalIndent(v, prefix, indent) -}