mirror of
https://github.com/paralus/paralus.git
synced 2026-05-07 08:56:42 +00:00
* 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>
41 lines
1.1 KiB
Go
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)
|
|
}
|