Files
paralus/pkg/converter/util.go
nirav-rafay c66bdc25cd restructure rcloud-base as a single base controller (#37)
* restructure rcloud-base as a single base controller
* updated master.rest
* moved sentry from internal to pkg as it is used by relay
* removing unused rpc and it's dependencies
* Fix usermgmt tests
* Don't redefine variables in rest file
Co-authored-by: Abin Simon <abin.simon@rafay.co>
2022-03-03 17:59:06 +05:30

41 lines
1.1 KiB
Go

package converter
import (
gojson "encoding/json"
apiv2 "github.com/RafaySystems/rcloud-base/proto/types/controller"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func ConvertToJsonRawMessage(data interface{}) gojson.RawMessage {
bytes, err := json.Marshal(data)
if err != nil {
_log.Errorw("failed to marshal", "err", err, "data", data)
}
return gojson.RawMessage(bytes)
}
func ConvertToObject(data []byte, dest interface{}) interface{} {
err := json.Unmarshal(data, &dest)
if err != nil {
_log.Errorw("failed to unmarshal", "err", err, "data", data)
}
return dest
}
// ToRuntimeObject converts JSON bytes into runtime object of latest version
func ToRuntimeObject(gvk schema.GroupVersionKind, b []byte) (runtime.Object, error) {
return toRuntimeObject(gvk, b)
}
// ToStepTemplate converts runtime.Object to StepTemplate
func ToStepTemplate(o runtime.Object) (apiv2.StepTemplate, error) {
return toStepTemplate(o)
}
// ToStepTemplate converts runtime.Object to StepTemplate
func StepObjectToStepTemplate(so apiv2.StepObject) (apiv2.StepTemplate, error) {
return stepObjectToStepTemplate(so)
}