pusher/biz/service/get_pusher_options.go

49 lines
1.3 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)
2024-05-21 14:01:28 +08:00
resp.Options = []*config.PusherOption{
{
Title: "AnPush",
Type: config.PusherConfigType_AnPush,
FormItems: toFormItems(config.AnPush{}),
},
{
Title: "邮箱",
Type: config.PusherConfigType_Email,
FormItems: toFormItems(config.EmailPush{}),
},
2024-05-20 17:57:25 +08:00
}
return
}
func toFormItems(in any) []*config.FormItem {
valueOfIn := reflect.TypeOf(in)
2024-05-20 17:57:25 +08:00
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(),
2024-05-20 17:57:25 +08:00
Require: true,
})
}
return items
}