diff --git a/pkg/hyper/encode.go b/pkg/hyper/encode.go new file mode 100644 index 0000000..0c684c4 --- /dev/null +++ b/pkg/hyper/encode.go @@ -0,0 +1,14 @@ +package hyper + +import jsoniter "github.com/json-iterator/go" + +func EncodeMap(policy map[string]any) []byte { + raw, _ := jsoniter.Marshal(policy) + return raw +} + +func DecodeMap(raw []byte) map[string]any { + var out map[string]any + _ = jsoniter.Unmarshal(raw, &out) + return out +} diff --git a/pkg/hyper/realm.go b/pkg/hyper/realm.go index 04a9919..fb3c2e6 100644 --- a/pkg/hyper/realm.go +++ b/pkg/hyper/realm.go @@ -6,7 +6,6 @@ import ( "reflect" "git.solsynth.dev/hydrogen/dealer/pkg/proto" - jsoniter "github.com/json-iterator/go" "gorm.io/datatypes" "gorm.io/gorm" ) @@ -43,7 +42,7 @@ func LinkRealm(tx *gorm.DB, table string, info *proto.RealmInfo) (BaseRealm, err Banner: info.Banner, IsPublic: info.IsPublic, IsCommunity: info.IsCommunity, - AccessPolicy: DecodeAccessPolicy(info.AccessPolicy), + AccessPolicy: DecodeMap(info.AccessPolicy), } return realm, tx.Table(table).Save(&realm).Error @@ -59,7 +58,7 @@ func LinkRealm(tx *gorm.DB, table string, info *proto.RealmInfo) (BaseRealm, err realm.Banner = info.Banner realm.IsPublic = info.IsPublic realm.IsCommunity = info.IsCommunity - realm.AccessPolicy = DecodeAccessPolicy(info.AccessPolicy) + realm.AccessPolicy = DecodeMap(info.AccessPolicy) var err error if !reflect.DeepEqual(prev, realm) { @@ -68,14 +67,3 @@ func LinkRealm(tx *gorm.DB, table string, info *proto.RealmInfo) (BaseRealm, err return realm, err } - -func EncodeAccessPolicy(policy map[string]any) []byte { - raw, _ := jsoniter.Marshal(policy) - return raw -} - -func DecodeAccessPolicy(raw []byte) map[string]any { - var policy map[string]any - _ = jsoniter.Unmarshal(raw, &policy) - return policy -}