k3s/vendor/github.com/bronze1man/goStrongswanVici/marshal.go

30 lines
755 B
Go
Raw Normal View History

2019-09-06 18:20:31 +00:00
package goStrongswanVici
import (
"encoding/json"
)
//concrete data type to general data type
// concrete data type like *Version
// general data type include map[string]interface{} []string string
// TODO make it faster
func ConvertToGeneral(concrete interface{}, general interface{}) (err error) {
b, err := json.Marshal(concrete)
if err != nil {
return
}
return json.Unmarshal(b, general)
}
// general data type to concrete data type
// concrete data type like *Version
// general data type include map[string]interface{} []string string
// TODO make it faster
func ConvertFromGeneral(general interface{}, concrete interface{}) (err error) {
b, err := json.Marshal(general)
if err != nil {
return
}
return json.Unmarshal(b, concrete)
}