pusher/biz/service/get_pusher_options.go

41 lines
1.2 KiB
Go
Raw Normal View History

2024-05-20 17:57:25 +08:00
package service
import (
"context"
"gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push"
"reflect"
)
type GetPusherOptionsService struct {
ctx context.Context
} // NewGetPusherOptionsService new GetPusherOptionsService
func NewGetPusherOptionsService(ctx context.Context) *GetPusherOptionsService {
return &GetPusherOptionsService{ctx: ctx}
}
// Run create note info
func (s *GetPusherOptionsService) Run() (resp *push.GetPusherOptionsResponse, err error) {
// Finish your business logic.
resp = new(push.GetPusherOptionsResponse)
resp.Options = map[config.PusherConfigType][]*config.FormItem{
config.PusherConfigType_AnPush: toFormItems(config.AnPush{}),
config.PusherConfigType_Email: toFormItems(config.EmailPush{}),
}
return
}
func toFormItems(in any) []*config.FormItem {
valueOfIn := reflect.ValueOf(in)
numOfFields := valueOfIn.NumField()
items := make([]*config.FormItem, 0, numOfFields)
for i := 0; i < numOfFields; i++ {
items = append(items, &config.FormItem{
Param: valueOfIn.Field(i).String(),
Type: valueOfIn.Field(i).Type().String(),
Require: true,
})
}
return items
}