pusher/biz/service/get_pusher_options.go
timerzz e099838d65
All checks were successful
Build image / build (push) Successful in 1m27s
feat 修改pusher options返回类型
2024-05-21 14:01:28 +08:00

49 lines
1.3 KiB
Go

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 = []*config.PusherOption{
{
Title: "AnPush",
Type: config.PusherConfigType_AnPush,
FormItems: toFormItems(config.AnPush{}),
},
{
Title: "邮箱",
Type: config.PusherConfigType_Email,
FormItems: toFormItems(config.EmailPush{}),
},
}
return
}
func toFormItems(in any) []*config.FormItem {
valueOfIn := reflect.TypeOf(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).Tag.Get("json"),
Type: valueOfIn.Field(i).Type.Kind().String(),
Require: true,
})
}
return items
}