@@ -2,41 +2,38 @@ package dns
22
33import (
44 "context"
5- "encoding/json"
65
76 instanceTypes "beryju.io/gravity/pkg/instance/types"
7+ "beryju.io/gravity/pkg/storage"
88 "go.uber.org/zap"
9+ "google.golang.org/protobuf/proto"
910
1011 "beryju.io/gravity/pkg/roles/dns/types"
1112 "github.com/swaggest/usecase"
1213 "github.com/swaggest/usecase/status"
1314)
1415
15- type RoleConfig struct {
16- Port int32 `json:"port"`
17- }
18-
19- func (r * Role ) decodeRoleConfig (raw []byte ) * RoleConfig {
20- def := RoleConfig {
16+ func (r * Role ) decodeRoleConfig (raw []byte ) * types.RoleConfig {
17+ def := types.RoleConfig {
2118 Port : 53 ,
2219 }
2320 if len (raw ) < 1 {
2421 return & def
2522 }
26- err := json . Unmarshal (raw , & def )
23+ conf , err := storage . Parse (raw , & def )
2724 if err != nil {
2825 r .log .Warn ("failed to decode role config" , zap .Error (err ))
2926 }
30- return & def
27+ return conf
3128}
3229
3330type APIRoleConfigOutput struct {
34- Config RoleConfig `json:"config" required:"true"`
31+ Config * types. RoleConfig `json:"config" required:"true"`
3532}
3633
3734func (r * Role ) APIRoleConfigGet () usecase.Interactor {
3835 u := usecase .NewInteractor (func (ctx context.Context , input struct {}, output * APIRoleConfigOutput ) error {
39- output .Config = * r .cfg
36+ output .Config = r .cfg
4037 return nil
4138 })
4239 u .SetName ("dns.get_role_config" )
@@ -46,12 +43,12 @@ func (r *Role) APIRoleConfigGet() usecase.Interactor {
4643}
4744
4845type APIRoleConfigInput struct {
49- Config RoleConfig `json:"config" required:"true"`
46+ Config * types. RoleConfig `json:"config" required:"true"`
5047}
5148
5249func (r * Role ) APIRoleConfigPut () usecase.Interactor {
5350 u := usecase .NewInteractor (func (ctx context.Context , input APIRoleConfigInput , output * struct {}) error {
54- jc , err := json .Marshal (input .Config )
51+ jc , err := proto .Marshal (input .Config )
5552 if err != nil {
5653 return status .Wrap (err , status .InvalidArgument )
5754 }
0 commit comments