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 }