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 }