From 4ec0cd156461215dcc9300c8e423defd8e7f935c Mon Sep 17 00:00:00 2001 From: timerzz Date: Mon, 20 May 2024 17:57:25 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build-push.yml | 16 + Dockerfile | 16 + biz/dal/init.go | 4 +- biz/dal/{pgsql => postgres}/init.go | 4 +- biz/handler/push/push_service.go | 80 +- biz/router/push/middleware.go | 40 + biz/router/push/push.go | 12 + biz/service/add.go | 17 +- biz/service/add_test.go | 10 +- biz/service/get_pusher_options.go | 40 + biz/service/get_pusher_options_test.go | 19 + biz/service/list.go | 29 + biz/service/push.go | 14 +- build.sh | 7 - conf/conf.go | 2 +- conf/dev/conf.yaml | 2 +- conf/online/conf.yaml | 2 +- gen.sh | 2 + go.mod | 10 +- go.sum | 24 +- handler.go | 16 +- idl/config.thrift | 33 +- idl/push.thrift | 37 +- kitex_gen/config/config.go | 1133 ++++++++++++++++++++- kitex_gen/config/k-config.go | 977 ++++++++++++++++-- kitex_gen/push/k-push.go | 596 ++++++++++- kitex_gen/push/push.go | 882 ++++++++++++++-- kitex_gen/push/pushservice/client.go | 14 +- kitex_gen/push/pushservice/pushservice.go | 46 +- main.go | 28 + model/pusher.go | 33 + model/pusher_test.go | 7 + pushers/anPush.go | 35 + pushers/controller.go | 67 ++ pushers/email.go | 35 + rpc/pusher/pusher_client.go | 62 ++ rpc/pusher/pusher_default.go | 45 + rpc/pusher/pusher_init.go | 44 + script/bootstrap.sh | 4 - 39 files changed, 4056 insertions(+), 388 deletions(-) create mode 100644 .gitea/workflows/build-push.yml create mode 100644 Dockerfile rename biz/dal/{pgsql => postgres}/init.go (73%) create mode 100644 biz/service/get_pusher_options.go create mode 100644 biz/service/get_pusher_options_test.go delete mode 100644 build.sh create mode 100644 gen.sh create mode 100644 model/pusher.go create mode 100644 model/pusher_test.go create mode 100644 pushers/anPush.go create mode 100644 pushers/controller.go create mode 100644 pushers/email.go create mode 100644 rpc/pusher/pusher_client.go create mode 100644 rpc/pusher/pusher_default.go create mode 100644 rpc/pusher/pusher_init.go delete mode 100644 script/bootstrap.sh diff --git a/.gitea/workflows/build-push.yml b/.gitea/workflows/build-push.yml new file mode 100644 index 0000000..3d8a0a3 --- /dev/null +++ b/.gitea/workflows/build-push.yml @@ -0,0 +1,16 @@ +name: Build image +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: build + run: docker build -t ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 -f Dockerfile . + - name: tag + run: docker tag ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest + - name: push 1.3 + run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:1.3 + - name: push latest + run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.IMAGE_NAME }}:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9445c5e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ + +FROM golang:1.22 as back +WORKDIR /build +COPY . /build +ARG CGO_ENABLED=0 +ARG GOPROXY=https://goproxy.cn,direct +ARG GOPRIVATE=gitea.timerzz.com +ARG GONOSUMDB=gitea.timerzz.com +ARG GONOPROXY=gitea.timerzz.com +RUN go build -trimpath -ldflags '-w -s' -o pusher . + +FROM alpine:latest +WORKDIR /work +COPY --from=back /build/run /work/ +ENTRYPOINT ["/work/pusher"] + diff --git a/biz/dal/init.go b/biz/dal/init.go index c5a03a3..ae7bcb8 100644 --- a/biz/dal/init.go +++ b/biz/dal/init.go @@ -1,9 +1,9 @@ package dal import ( - "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal/pgsql" + "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal/postgres" ) func Init() { - pgsql.Init() + postgres.Init() } diff --git a/biz/dal/pgsql/init.go b/biz/dal/postgres/init.go similarity index 73% rename from biz/dal/pgsql/init.go rename to biz/dal/postgres/init.go index 8b419ba..117d856 100644 --- a/biz/dal/pgsql/init.go +++ b/biz/dal/postgres/init.go @@ -1,7 +1,8 @@ -package pgsql +package postgres import ( "gitea.timerzz.com/kedaya_haitao/pusher/conf" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" "gorm.io/driver/postgres" "gorm.io/gorm" @@ -22,4 +23,5 @@ func Init() { if err != nil { panic(err) } + _ = DB.AutoMigrate(&config.PusherConfig{}) } diff --git a/biz/handler/push/push_service.go b/biz/handler/push/push_service.go index cb84e38..8e73bf6 100644 --- a/biz/handler/push/push_service.go +++ b/biz/handler/push/push_service.go @@ -4,7 +4,85 @@ package push import ( "context" - + "gitea.timerzz.com/kedaya_haitao/pusher/biz/service" + config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" ) + +// Push . +// @router /api/v1/push [POST] +func Push(ctx context.Context, c *app.RequestContext) { + var err error + var req push.PushReq + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp, err := service.NewPushService(ctx).Run(&req) + + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + c.JSON(consts.StatusOK, resp) +} + +// Add . +// @router /api/v1/pushers [POST] +func Add(ctx context.Context, c *app.RequestContext) { + var err error + var req config.PusherConfig + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(push.Resp) + + resp, err = service.NewAddService(ctx).Run(&req) + + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + c.JSON(consts.StatusOK, resp) +} + +// List . +// @router /api/v1/pushers [GET] +func List(ctx context.Context, c *app.RequestContext) { + var err error + var req push.ListPusherRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + var resp *push.ListPusherResponse + resp, err = service.NewListService(ctx).Run(&req) + + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + c.JSON(consts.StatusOK, resp) +} + +// GetPusherOptions . +// @router /api/v1/pushers/options [GET] +func GetPusherOptions(ctx context.Context, c *app.RequestContext) { + resp, err := service.NewGetPusherOptionsService(ctx).Run() + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + c.JSON(consts.StatusOK, resp) +} diff --git a/biz/router/push/middleware.go b/biz/router/push/middleware.go index b119878..f16c9f7 100644 --- a/biz/router/push/middleware.go +++ b/biz/router/push/middleware.go @@ -5,3 +5,43 @@ package push import ( "github.com/cloudwego/hertz/pkg/app" ) + +func rootMw() []app.HandlerFunc { + // your code... + return nil +} + +func _apiMw() []app.HandlerFunc { + // your code... + return nil +} + +func _v1Mw() []app.HandlerFunc { + // your code... + return nil +} + +func _pushMw() []app.HandlerFunc { + // your code... + return nil +} + +func _pushersMw() []app.HandlerFunc { + // your code... + return nil +} + +func _addMw() []app.HandlerFunc { + // your code... + return nil +} + +func _getpusheroptionsMw() []app.HandlerFunc { + // your code... + return nil +} + +func _listMw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/biz/router/push/push.go b/biz/router/push/push.go index 6bd719e..2444066 100644 --- a/biz/router/push/push.go +++ b/biz/router/push/push.go @@ -16,4 +16,16 @@ import ( // Register register routes based on the IDL 'api.${HTTP Method}' annotation. func Register(r *server.Hertz) { + root := r.Group("/", rootMw()...) + { + _api := root.Group("/api", _apiMw()...) + { + _v1 := _api.Group("/v1", _v1Mw()...) + _v1.POST("/push", append(_pushMw(), push.Push)...) + _v1.POST("/pushers", append(_addMw(), push.Add)...) + _pushers := _v1.Group("/pushers", _pushersMw()...) + _pushers.GET("/options", append(_getpusheroptionsMw(), push.GetPusherOptions)...) + _v1.GET("/pushers", append(_listMw(), push.List)...) + } + } } diff --git a/biz/service/add.go b/biz/service/add.go index 165b14f..ea497b0 100644 --- a/biz/service/add.go +++ b/biz/service/add.go @@ -2,21 +2,26 @@ package service import ( "context" + "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal/postgres" config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" ) type AddService struct { ctx context.Context -} - -// NewAddService new AddService +} // NewAddService new AddService func NewAddService(ctx context.Context) *AddService { return &AddService{ctx: ctx} } // Run create note info -func (s *AddService) Run(req *config.PushConfig) error { +func (s *AddService) Run(req *config.PusherConfig) (resp *push.Resp, err error) { // Finish your business logic. - - return nil + resp = push.NewResp() + err = postgres.DB.Create(req).Error + if err != nil { + resp.Code = 100 + resp.Msg = err.Error() + } + return } diff --git a/biz/service/add_test.go b/biz/service/add_test.go index bda6354..2bc0c8f 100644 --- a/biz/service/add_test.go +++ b/biz/service/add_test.go @@ -3,6 +3,7 @@ package service import ( "context" config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" "testing" ) @@ -11,12 +12,11 @@ func TestAdd_Run(t *testing.T) { s := NewAddService(ctx) // init req and assert value - req := &config.PushConfig{} + req := &config.PusherConfig{} + resp, err := s.Run(req) + t.Logf("err: %v", err) + t.Logf("resp: %v", resp) - err := s.Run(req) - if err != nil { - t.Errorf("unexpected error: %v", err) - } // todo: edit your unit test } diff --git a/biz/service/get_pusher_options.go b/biz/service/get_pusher_options.go new file mode 100644 index 0000000..5e6f715 --- /dev/null +++ b/biz/service/get_pusher_options.go @@ -0,0 +1,40 @@ +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 +} diff --git a/biz/service/get_pusher_options_test.go b/biz/service/get_pusher_options_test.go new file mode 100644 index 0000000..e83d411 --- /dev/null +++ b/biz/service/get_pusher_options_test.go @@ -0,0 +1,19 @@ +package service + +import ( + "context" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" + "testing" +) + +func TestGetPusherOptions_Run(t *testing.T) { + ctx := context.Background() + s := NewGetPusherOptionsService(ctx) + // init req and assert value + resp, err := s.Run() + t.Logf("err: %v", err) + t.Logf("resp: %v", resp) + + // todo: edit your unit test + +} diff --git a/biz/service/list.go b/biz/service/list.go index f5faa33..d1854d5 100644 --- a/biz/service/list.go +++ b/biz/service/list.go @@ -2,6 +2,9 @@ package service import ( "context" + "fmt" + "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal/postgres" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" ) @@ -15,6 +18,32 @@ func NewListService(ctx context.Context) *ListService { // Run create note info func (s *ListService) Run(req *push.ListPusherRequest) (resp *push.ListPusherResponse, err error) { // Finish your business logic. + tx := postgres.DB + if req.Keyword != "" { + tx = tx.Where("name LIKE ? or remark LIKE ?", fmt.Sprintf("%%%s%%", req.Keyword), fmt.Sprintf("%%%s%%", req.Keyword)) + } + resp = new(push.ListPusherResponse) + if err = tx.Model(&config.PusherConfig{}).Find(&resp.List).Error; err != nil { + return nil, fmt.Errorf("查询总数失败:%v", err) + } + resp.Total = int64(len(resp.List)) + if req.All || resp.Total == 0 { + return + } + + // 查询列表 + if req.Page < 1 { + req.Page = 1 + } + if req.Size < 1 { + req.Size = 10 + } + offset := (req.Page - 1) * int64(req.Size) + + if err = tx.Order("created_at desc").Limit(int(req.Size)).Offset(int(offset)). + Find(&resp.List).Error; err != nil { + return nil, fmt.Errorf("查询列表失败:%v", err) + } return } diff --git a/biz/service/push.go b/biz/service/push.go index 3dbb2c5..3a9df23 100644 --- a/biz/service/push.go +++ b/biz/service/push.go @@ -2,7 +2,9 @@ package service import ( "context" + "fmt" push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" + "gitea.timerzz.com/kedaya_haitao/pusher/pushers" ) type PushService struct { @@ -13,8 +15,16 @@ func NewPushService(ctx context.Context) *PushService { } // Run create note info -func (s *PushService) Run(req *push.PushReq) (resp *push.PushResp, err error) { +func (s *PushService) Run(req *push.PushReq) (resp *push.Resp, err error) { // Finish your business logic. - + if len(req.Ids) == 0 { + return nil, fmt.Errorf("缺少id") + } + resp = push.NewResp() + err = pushers.Push(s.ctx, req.Ids, req.Title, req.Content) + if err != nil { + resp.Code = 100 + resp.Msg = err.Error() + } return } diff --git a/build.sh b/build.sh deleted file mode 100644 index 9bb49ce..0000000 --- a/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -RUN_NAME="pusher" -mkdir -p output/bin output/conf -cp script/* output/ -cp -r conf/* output/conf -chmod +x output/bootstrap.sh -go build -o output/bin/${RUN_NAME} \ No newline at end of file diff --git a/conf/conf.go b/conf/conf.go index 9440335..a5e1ad8 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -54,7 +54,7 @@ func GetConf() *Config { } func initConf() { - prefix := "conf" + prefix := "/data" confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml")) content, err := ioutil.ReadFile(confFileRelPath) if err != nil { diff --git a/conf/dev/conf.yaml b/conf/dev/conf.yaml index 348eac0..13a4d3c 100644 --- a/conf/dev/conf.yaml +++ b/conf/dev/conf.yaml @@ -14,4 +14,4 @@ registry: password: "" db: - dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" + dsn: "host=192.168.31.55 user=timerzz password=zhhg1997 dbname=kedaya_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai" diff --git a/conf/online/conf.yaml b/conf/online/conf.yaml index 348eac0..3a0db7a 100644 --- a/conf/online/conf.yaml +++ b/conf/online/conf.yaml @@ -14,4 +14,4 @@ registry: password: "" db: - dsn: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local" + dsn: "host=192.168.31.55 user=timerzz password=zhhg1997 dbname=kedaya port=5432 sslmode=disable TimeZone=Asia/Shanghai" diff --git a/gen.sh b/gen.sh new file mode 100644 index 0000000..f0c0bb2 --- /dev/null +++ b/gen.sh @@ -0,0 +1,2 @@ +cwgo server --type RPC --idl .\idl\push.thrift --service pusher --module gitea.timerzz.com/kedaya_haitao/pusher --hex +cwgo client --type RPC --idl .\idl\push.thrift --service pusher --module gitea.timerzz.com/kedaya_haitao/pusher \ No newline at end of file diff --git a/go.mod b/go.mod index cf85342..75193ba 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/apache/thrift v0.13.0 github.com/cloudwego/hertz v0.9.0 github.com/cloudwego/kitex v0.9.1 + github.com/go-resty/resty/v2 v2.13.1 github.com/kitex-contrib/obs-opentelemetry/logging/logrus v0.0.0-20240515092919-1f776656cb66 github.com/kr/pretty v0.3.0 go.uber.org/zap v1.27.0 @@ -62,15 +63,16 @@ require ( github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/wneessen/go-mail v0.4.1 // indirect go.opentelemetry.io/otel v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/arch v0.2.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 7dc2d85..8b06943 100644 --- a/go.sum +++ b/go.sum @@ -116,6 +116,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= +github.com/go-resty/resty/v2 v2.13.1 h1:x+LHXBI2nMB1vqndymf26quycC4aggYJ7DECYbiz03g= +github.com/go-resty/resty/v2 v2.13.1/go.mod h1:GznXlLxkq6Nh4sU59rPmUw3VtgpO3aS96ORAI6Q7d+0= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -255,6 +257,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2 github.com/v2pro/plz v0.0.0-20221028024117-e5f9aec5b631/go.mod h1:3gacX+hQo+xvl0vtLqCMufzxuNCwt4geAVOMt2LQYfE= github.com/v2pro/quokka v0.0.0-20171201153428-382cb39c6ee6/go.mod h1:0VP5W9AFNVWU8C1QLNeVg8TvzoEkIHWZ4vxtxEVFWUY= github.com/v2pro/wombat v0.0.0-20180402055224-a56dbdcddef2/go.mod h1:wen8nMxrRrUmXnRwH+3wGAW+hyYTHcOrTNhMpxyp/i0= +github.com/wneessen/go-mail v0.4.1 h1:m2rSg/sc8FZQCdtrV5M8ymHYOFrC6KJAQAIcgrXvqoo= +github.com/wneessen/go-mail v0.4.1/go.mod h1:zxOlafWCP/r6FEhAaRgH4IC1vg2YXxO0Nar9u0IScZ8= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -287,8 +291,10 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -340,8 +346,10 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -382,13 +390,17 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -397,8 +409,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/handler.go b/handler.go index 0222037..8d0a318 100644 --- a/handler.go +++ b/handler.go @@ -2,7 +2,6 @@ package main import ( "context" - "gitea.timerzz.com/kedaya_haitao/pusher/biz/service" config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" @@ -12,17 +11,17 @@ import ( type PushServiceImpl struct{} // Push implements the PushServiceImpl interface. -func (s *PushServiceImpl) Push(ctx context.Context, req *push.PushReq) (resp *push.PushResp, err error) { +func (s *PushServiceImpl) Push(ctx context.Context, req *push.PushReq) (resp *push.Resp, err error) { resp, err = service.NewPushService(ctx).Run(req) return resp, err } // Add implements the PushServiceImpl interface. -func (s *PushServiceImpl) Add(ctx context.Context, req *config.PushConfig) (err error) { - err = service.NewAddService(ctx).Run(req) +func (s *PushServiceImpl) Add(ctx context.Context, req *config.PusherConfig) (resp *push.Resp, err error) { + resp, err = service.NewAddService(ctx).Run(req) - return err + return resp, err } // List implements the PushServiceImpl interface. @@ -31,3 +30,10 @@ func (s *PushServiceImpl) List(ctx context.Context, req *push.ListPusherRequest) return resp, err } + +// GetPusherOptions implements the PushServiceImpl interface. +func (s *PushServiceImpl) GetPusherOptions(ctx context.Context) (resp *push.GetPusherOptionsResponse, err error) { + resp, err = service.NewGetPusherOptionsService(ctx).Run() + + return resp, err +} diff --git a/idl/config.thrift b/idl/config.thrift index 917b29f..ab97132 100644 --- a/idl/config.thrift +++ b/idl/config.thrift @@ -1,8 +1,33 @@ -struct PushConfig { +enum PusherConfigType { + AnPush = 1, + Email +} + +struct PusherConfig { 1: i64 id 2: i64 createdAt - 3: i8 type - 4: string name + 3: PusherConfigType type + 4: required string name 5: string remark - 6: string option + 6: required string option +} + +struct FormItem { + 1: string param + 2: string type + 3: bool require +} + +struct AnPush { + 1: string token + 2: string channel +} + +struct EmailPush { + 1: string from + 2: string to + 3: string username + 4: string password + 5: string host + 6: i32 port } \ No newline at end of file diff --git a/idl/push.thrift b/idl/push.thrift index 91c9026..a4bdf56 100644 --- a/idl/push.thrift +++ b/idl/push.thrift @@ -1,31 +1,36 @@ include "config.thrift" struct PushReq { - 1: required i64 id - 2: required string title - 3: required string content + 1: required list ids (api.body="ids"); + 2: required string title (api.body="title"); + 3: required string content (api.body="content"); } -struct PushResp { - 1: required i64 errCode - 2: string errMsg - 3: string msgId +struct Resp { + 1: required i64 code (api.body="code"); + 2: string msg (api.body="msg"); + 3: string msgId (api.body="msgId"); } struct ListPusherRequest { - 1: string keyword - 2: optional i64 page = 10 - 3: optional i16 size = 1 - 4: bool all + 1: string keyword (api.query="keyword"); + 2: optional i64 page = 10 (api.query="page"); + 3: optional i16 size = 1 (api.query="size"); + 4: bool all (api.query="all"); } struct ListPusherResponse { - 1: i64 total - 2: list list + 1: i64 total (api.body="total"); + 2: list list (api.body="list"); +} + +struct GetPusherOptionsResponse { + 1: map> options } service PushService{ - PushResp Push(1: PushReq req) - void Add(1: config.PushConfig req) - ListPusherResponse List(1: ListPusherRequest req) + Resp Push(1: PushReq req) (api.post="/api/v1/push"); + Resp Add(1: config.PusherConfig req) (api.post="/api/v1/pushers"); + ListPusherResponse List(1: ListPusherRequest req) (api.get="/api/v1/pushers"); + GetPusherOptionsResponse GetPusherOptions() (api.get="/api/v1/pushers/options") } diff --git a/kitex_gen/config/config.go b/kitex_gen/config/config.go index e542fe5..18265f7 100644 --- a/kitex_gen/config/config.go +++ b/kitex_gen/config/config.go @@ -3,71 +3,115 @@ package config import ( + "database/sql" + "database/sql/driver" "fmt" "github.com/apache/thrift/lib/go/thrift" "strings" ) -type PushConfig struct { - Id int64 `thrift:"id,1" frugal:"1,default,i64" form:"id" json:"id" query:"id"` - CreatedAt int64 `thrift:"createdAt,2" frugal:"2,default,i64" form:"createdAt" json:"createdAt" query:"createdAt"` - Type int8 `thrift:"type,3" frugal:"3,default,i8" form:"type" json:"type" query:"type"` - Name string `thrift:"name,4" frugal:"4,default,string" form:"name" json:"name" query:"name"` - Remark string `thrift:"remark,5" frugal:"5,default,string" form:"remark" json:"remark" query:"remark"` - Option string `thrift:"option,6" frugal:"6,default,string" form:"option" json:"option" query:"option"` +type PusherConfigType int64 + +const ( + PusherConfigType_AnPush PusherConfigType = 1 + PusherConfigType_Email PusherConfigType = 2 +) + +func (p PusherConfigType) String() string { + switch p { + case PusherConfigType_AnPush: + return "AnPush" + case PusherConfigType_Email: + return "Email" + } + return "" } -func NewPushConfig() *PushConfig { - return &PushConfig{} +func PusherConfigTypeFromString(s string) (PusherConfigType, error) { + switch s { + case "AnPush": + return PusherConfigType_AnPush, nil + case "Email": + return PusherConfigType_Email, nil + } + return PusherConfigType(0), fmt.Errorf("not a valid PusherConfigType string") } -func (p *PushConfig) InitDefault() { - *p = PushConfig{} +func PusherConfigTypePtr(v PusherConfigType) *PusherConfigType { return &v } +func (p *PusherConfigType) Scan(value interface{}) (err error) { + var result sql.NullInt64 + err = result.Scan(value) + *p = PusherConfigType(result.Int64) + return } -func (p *PushConfig) GetId() (v int64) { +func (p *PusherConfigType) Value() (driver.Value, error) { + if p == nil { + return nil, nil + } + return int64(*p), nil +} + +type PusherConfig struct { + Id int64 `thrift:"id,1" frugal:"1,default,i64" json:"id"` + CreatedAt int64 `thrift:"createdAt,2" frugal:"2,default,i64" json:"createdAt"` + Type PusherConfigType `thrift:"type,3" frugal:"3,default,PusherConfigType" json:"type"` + Name string `thrift:"name,4,required" frugal:"4,required,string" json:"name"` + Remark string `thrift:"remark,5" frugal:"5,default,string" json:"remark"` + Option string `thrift:"option,6,required" frugal:"6,required,string" json:"option"` +} + +func NewPusherConfig() *PusherConfig { + return &PusherConfig{} +} + +func (p *PusherConfig) InitDefault() { + *p = PusherConfig{} +} + +func (p *PusherConfig) GetId() (v int64) { return p.Id } -func (p *PushConfig) GetCreatedAt() (v int64) { +func (p *PusherConfig) GetCreatedAt() (v int64) { return p.CreatedAt } -func (p *PushConfig) GetType() (v int8) { +func (p *PusherConfig) GetType() (v PusherConfigType) { return p.Type } -func (p *PushConfig) GetName() (v string) { +func (p *PusherConfig) GetName() (v string) { return p.Name } -func (p *PushConfig) GetRemark() (v string) { +func (p *PusherConfig) GetRemark() (v string) { return p.Remark } -func (p *PushConfig) GetOption() (v string) { +func (p *PusherConfig) GetOption() (v string) { return p.Option } -func (p *PushConfig) SetId(val int64) { +func (p *PusherConfig) SetId(val int64) { p.Id = val } -func (p *PushConfig) SetCreatedAt(val int64) { +func (p *PusherConfig) SetCreatedAt(val int64) { p.CreatedAt = val } -func (p *PushConfig) SetType(val int8) { +func (p *PusherConfig) SetType(val PusherConfigType) { p.Type = val } -func (p *PushConfig) SetName(val string) { +func (p *PusherConfig) SetName(val string) { p.Name = val } -func (p *PushConfig) SetRemark(val string) { +func (p *PusherConfig) SetRemark(val string) { p.Remark = val } -func (p *PushConfig) SetOption(val string) { +func (p *PusherConfig) SetOption(val string) { p.Option = val } -var fieldIDToName_PushConfig = map[int16]string{ +var fieldIDToName_PusherConfig = map[int16]string{ 1: "id", 2: "createdAt", 3: "type", @@ -76,10 +120,12 @@ var fieldIDToName_PushConfig = map[int16]string{ 6: "option", } -func (p *PushConfig) Read(iprot thrift.TProtocol) (err error) { +func (p *PusherConfig) Read(iprot thrift.TProtocol) (err error) { var fieldTypeId thrift.TType var fieldId int16 + var issetName bool = false + var issetOption bool = false if _, err = iprot.ReadStructBegin(); err != nil { goto ReadStructBeginError @@ -112,7 +158,7 @@ func (p *PushConfig) Read(iprot thrift.TProtocol) (err error) { goto SkipFieldError } case 3: - if fieldTypeId == thrift.BYTE { + if fieldTypeId == thrift.I32 { if err = p.ReadField3(iprot); err != nil { goto ReadFieldError } @@ -124,6 +170,7 @@ func (p *PushConfig) Read(iprot thrift.TProtocol) (err error) { if err = p.ReadField4(iprot); err != nil { goto ReadFieldError } + issetName = true } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } @@ -140,6 +187,7 @@ func (p *PushConfig) Read(iprot thrift.TProtocol) (err error) { if err = p.ReadField6(iprot); err != nil { goto ReadFieldError } + issetOption = true } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } @@ -156,13 +204,22 @@ func (p *PushConfig) Read(iprot thrift.TProtocol) (err error) { goto ReadStructEndError } + if !issetName { + fieldId = 4 + goto RequiredFieldNotSetError + } + + if !issetOption { + fieldId = 6 + goto RequiredFieldNotSetError + } return nil ReadStructBeginError: return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) ReadFieldBeginError: return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushConfig[fieldId]), err) + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PusherConfig[fieldId]), err) SkipFieldError: return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) @@ -170,9 +227,11 @@ ReadFieldEndError: return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) ReadStructEndError: return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PusherConfig[fieldId])) } -func (p *PushConfig) ReadField1(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField1(iprot thrift.TProtocol) error { var _field int64 if v, err := iprot.ReadI64(); err != nil { @@ -183,7 +242,7 @@ func (p *PushConfig) ReadField1(iprot thrift.TProtocol) error { p.Id = _field return nil } -func (p *PushConfig) ReadField2(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField2(iprot thrift.TProtocol) error { var _field int64 if v, err := iprot.ReadI64(); err != nil { @@ -194,18 +253,18 @@ func (p *PushConfig) ReadField2(iprot thrift.TProtocol) error { p.CreatedAt = _field return nil } -func (p *PushConfig) ReadField3(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField3(iprot thrift.TProtocol) error { - var _field int8 - if v, err := iprot.ReadByte(); err != nil { + var _field PusherConfigType + if v, err := iprot.ReadI32(); err != nil { return err } else { - _field = v + _field = PusherConfigType(v) } p.Type = _field return nil } -func (p *PushConfig) ReadField4(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField4(iprot thrift.TProtocol) error { var _field string if v, err := iprot.ReadString(); err != nil { @@ -216,7 +275,7 @@ func (p *PushConfig) ReadField4(iprot thrift.TProtocol) error { p.Name = _field return nil } -func (p *PushConfig) ReadField5(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField5(iprot thrift.TProtocol) error { var _field string if v, err := iprot.ReadString(); err != nil { @@ -227,7 +286,7 @@ func (p *PushConfig) ReadField5(iprot thrift.TProtocol) error { p.Remark = _field return nil } -func (p *PushConfig) ReadField6(iprot thrift.TProtocol) error { +func (p *PusherConfig) ReadField6(iprot thrift.TProtocol) error { var _field string if v, err := iprot.ReadString(); err != nil { @@ -239,9 +298,9 @@ func (p *PushConfig) ReadField6(iprot thrift.TProtocol) error { return nil } -func (p *PushConfig) Write(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) Write(oprot thrift.TProtocol) (err error) { var fieldId int16 - if err = oprot.WriteStructBegin("PushConfig"); err != nil { + if err = oprot.WriteStructBegin("PusherConfig"); err != nil { goto WriteStructBeginError } if p != nil { @@ -287,7 +346,7 @@ WriteStructEndError: return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) } -func (p *PushConfig) writeField1(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) writeField1(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { goto WriteFieldBeginError } @@ -304,7 +363,7 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) } -func (p *PushConfig) writeField2(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) writeField2(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("createdAt", thrift.I64, 2); err != nil { goto WriteFieldBeginError } @@ -321,11 +380,11 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) } -func (p *PushConfig) writeField3(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("type", thrift.BYTE, 3); err != nil { +func (p *PusherConfig) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("type", thrift.I32, 3); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteByte(p.Type); err != nil { + if err := oprot.WriteI32(int32(p.Type)); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -338,7 +397,7 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) } -func (p *PushConfig) writeField4(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) writeField4(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("name", thrift.STRING, 4); err != nil { goto WriteFieldBeginError } @@ -355,7 +414,7 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err) } -func (p *PushConfig) writeField5(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) writeField5(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("remark", thrift.STRING, 5); err != nil { goto WriteFieldBeginError } @@ -372,7 +431,7 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err) } -func (p *PushConfig) writeField6(oprot thrift.TProtocol) (err error) { +func (p *PusherConfig) writeField6(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("option", thrift.STRING, 6); err != nil { goto WriteFieldBeginError } @@ -389,15 +448,15 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err) } -func (p *PushConfig) String() string { +func (p *PusherConfig) String() string { if p == nil { return "" } - return fmt.Sprintf("PushConfig(%+v)", *p) + return fmt.Sprintf("PusherConfig(%+v)", *p) } -func (p *PushConfig) DeepEqual(ano *PushConfig) bool { +func (p *PusherConfig) DeepEqual(ano *PusherConfig) bool { if p == ano { return true } else if p == nil || ano == nil { @@ -424,45 +483,1009 @@ func (p *PushConfig) DeepEqual(ano *PushConfig) bool { return true } -func (p *PushConfig) Field1DeepEqual(src int64) bool { +func (p *PusherConfig) Field1DeepEqual(src int64) bool { if p.Id != src { return false } return true } -func (p *PushConfig) Field2DeepEqual(src int64) bool { +func (p *PusherConfig) Field2DeepEqual(src int64) bool { if p.CreatedAt != src { return false } return true } -func (p *PushConfig) Field3DeepEqual(src int8) bool { +func (p *PusherConfig) Field3DeepEqual(src PusherConfigType) bool { if p.Type != src { return false } return true } -func (p *PushConfig) Field4DeepEqual(src string) bool { +func (p *PusherConfig) Field4DeepEqual(src string) bool { if strings.Compare(p.Name, src) != 0 { return false } return true } -func (p *PushConfig) Field5DeepEqual(src string) bool { +func (p *PusherConfig) Field5DeepEqual(src string) bool { if strings.Compare(p.Remark, src) != 0 { return false } return true } -func (p *PushConfig) Field6DeepEqual(src string) bool { +func (p *PusherConfig) Field6DeepEqual(src string) bool { if strings.Compare(p.Option, src) != 0 { return false } return true } + +type FormItem struct { + Param string `thrift:"param,1" frugal:"1,default,string" json:"param"` + Type string `thrift:"type,2" frugal:"2,default,string" json:"type"` + Require bool `thrift:"require,3" frugal:"3,default,bool" json:"require"` +} + +func NewFormItem() *FormItem { + return &FormItem{} +} + +func (p *FormItem) InitDefault() { + *p = FormItem{} +} + +func (p *FormItem) GetParam() (v string) { + return p.Param +} + +func (p *FormItem) GetType() (v string) { + return p.Type +} + +func (p *FormItem) GetRequire() (v bool) { + return p.Require +} +func (p *FormItem) SetParam(val string) { + p.Param = val +} +func (p *FormItem) SetType(val string) { + p.Type = val +} +func (p *FormItem) SetRequire(val bool) { + p.Require = val +} + +var fieldIDToName_FormItem = map[int16]string{ + 1: "param", + 2: "type", + 3: "require", +} + +func (p *FormItem) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 3: + if fieldTypeId == thrift.BOOL { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_FormItem[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *FormItem) ReadField1(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Param = _field + return nil +} +func (p *FormItem) ReadField2(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Type = _field + return nil +} +func (p *FormItem) ReadField3(iprot thrift.TProtocol) error { + + var _field bool + if v, err := iprot.ReadBool(); err != nil { + return err + } else { + _field = v + } + p.Require = _field + return nil +} + +func (p *FormItem) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("FormItem"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *FormItem) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("param", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Param); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *FormItem) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("type", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Type); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *FormItem) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("require", thrift.BOOL, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteBool(p.Require); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *FormItem) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("FormItem(%+v)", *p) + +} + +func (p *FormItem) DeepEqual(ano *FormItem) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Param) { + return false + } + if !p.Field2DeepEqual(ano.Type) { + return false + } + if !p.Field3DeepEqual(ano.Require) { + return false + } + return true +} + +func (p *FormItem) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Param, src) != 0 { + return false + } + return true +} +func (p *FormItem) Field2DeepEqual(src string) bool { + + if strings.Compare(p.Type, src) != 0 { + return false + } + return true +} +func (p *FormItem) Field3DeepEqual(src bool) bool { + + if p.Require != src { + return false + } + return true +} + +type AnPush struct { + Token string `thrift:"token,1" frugal:"1,default,string" json:"token"` + Channel string `thrift:"channel,2" frugal:"2,default,string" json:"channel"` +} + +func NewAnPush() *AnPush { + return &AnPush{} +} + +func (p *AnPush) InitDefault() { + *p = AnPush{} +} + +func (p *AnPush) GetToken() (v string) { + return p.Token +} + +func (p *AnPush) GetChannel() (v string) { + return p.Channel +} +func (p *AnPush) SetToken(val string) { + p.Token = val +} +func (p *AnPush) SetChannel(val string) { + p.Channel = val +} + +var fieldIDToName_AnPush = map[int16]string{ + 1: "token", + 2: "channel", +} + +func (p *AnPush) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AnPush[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *AnPush) ReadField1(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Token = _field + return nil +} +func (p *AnPush) ReadField2(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Channel = _field + return nil +} + +func (p *AnPush) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("AnPush"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *AnPush) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("token", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Token); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *AnPush) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("channel", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Channel); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *AnPush) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AnPush(%+v)", *p) + +} + +func (p *AnPush) DeepEqual(ano *AnPush) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Token) { + return false + } + if !p.Field2DeepEqual(ano.Channel) { + return false + } + return true +} + +func (p *AnPush) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Token, src) != 0 { + return false + } + return true +} +func (p *AnPush) Field2DeepEqual(src string) bool { + + if strings.Compare(p.Channel, src) != 0 { + return false + } + return true +} + +type EmailPush struct { + From string `thrift:"from,1" frugal:"1,default,string" json:"from"` + To string `thrift:"to,2" frugal:"2,default,string" json:"to"` + Username string `thrift:"username,3" frugal:"3,default,string" json:"username"` + Password string `thrift:"password,4" frugal:"4,default,string" json:"password"` + Host string `thrift:"host,5" frugal:"5,default,string" json:"host"` + Port int32 `thrift:"port,6" frugal:"6,default,i32" json:"port"` +} + +func NewEmailPush() *EmailPush { + return &EmailPush{} +} + +func (p *EmailPush) InitDefault() { + *p = EmailPush{} +} + +func (p *EmailPush) GetFrom() (v string) { + return p.From +} + +func (p *EmailPush) GetTo() (v string) { + return p.To +} + +func (p *EmailPush) GetUsername() (v string) { + return p.Username +} + +func (p *EmailPush) GetPassword() (v string) { + return p.Password +} + +func (p *EmailPush) GetHost() (v string) { + return p.Host +} + +func (p *EmailPush) GetPort() (v int32) { + return p.Port +} +func (p *EmailPush) SetFrom(val string) { + p.From = val +} +func (p *EmailPush) SetTo(val string) { + p.To = val +} +func (p *EmailPush) SetUsername(val string) { + p.Username = val +} +func (p *EmailPush) SetPassword(val string) { + p.Password = val +} +func (p *EmailPush) SetHost(val string) { + p.Host = val +} +func (p *EmailPush) SetPort(val int32) { + p.Port = val +} + +var fieldIDToName_EmailPush = map[int16]string{ + 1: "from", + 2: "to", + 3: "username", + 4: "password", + 5: "host", + 6: "port", +} + +func (p *EmailPush) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 3: + if fieldTypeId == thrift.STRING { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 4: + if fieldTypeId == thrift.STRING { + if err = p.ReadField4(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 5: + if fieldTypeId == thrift.STRING { + if err = p.ReadField5(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 6: + if fieldTypeId == thrift.I32 { + if err = p.ReadField6(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EmailPush[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EmailPush) ReadField1(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.From = _field + return nil +} +func (p *EmailPush) ReadField2(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.To = _field + return nil +} +func (p *EmailPush) ReadField3(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Username = _field + return nil +} +func (p *EmailPush) ReadField4(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Password = _field + return nil +} +func (p *EmailPush) ReadField5(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.Host = _field + return nil +} +func (p *EmailPush) ReadField6(iprot thrift.TProtocol) error { + + var _field int32 + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + _field = v + } + p.Port = _field + return nil +} + +func (p *EmailPush) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EmailPush"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + if err = p.writeField4(oprot); err != nil { + fieldId = 4 + goto WriteFieldError + } + if err = p.writeField5(oprot); err != nil { + fieldId = 5 + goto WriteFieldError + } + if err = p.writeField6(oprot); err != nil { + fieldId = 6 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EmailPush) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("from", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.From); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EmailPush) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("to", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.To); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *EmailPush) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("username", thrift.STRING, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Username); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *EmailPush) writeField4(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("password", thrift.STRING, 4); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Password); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 4 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err) +} + +func (p *EmailPush) writeField5(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("host", thrift.STRING, 5); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Host); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 5 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err) +} + +func (p *EmailPush) writeField6(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("port", thrift.I32, 6); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(p.Port); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 6 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err) +} + +func (p *EmailPush) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EmailPush(%+v)", *p) + +} + +func (p *EmailPush) DeepEqual(ano *EmailPush) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.From) { + return false + } + if !p.Field2DeepEqual(ano.To) { + return false + } + if !p.Field3DeepEqual(ano.Username) { + return false + } + if !p.Field4DeepEqual(ano.Password) { + return false + } + if !p.Field5DeepEqual(ano.Host) { + return false + } + if !p.Field6DeepEqual(ano.Port) { + return false + } + return true +} + +func (p *EmailPush) Field1DeepEqual(src string) bool { + + if strings.Compare(p.From, src) != 0 { + return false + } + return true +} +func (p *EmailPush) Field2DeepEqual(src string) bool { + + if strings.Compare(p.To, src) != 0 { + return false + } + return true +} +func (p *EmailPush) Field3DeepEqual(src string) bool { + + if strings.Compare(p.Username, src) != 0 { + return false + } + return true +} +func (p *EmailPush) Field4DeepEqual(src string) bool { + + if strings.Compare(p.Password, src) != 0 { + return false + } + return true +} +func (p *EmailPush) Field5DeepEqual(src string) bool { + + if strings.Compare(p.Host, src) != 0 { + return false + } + return true +} +func (p *EmailPush) Field6DeepEqual(src int32) bool { + + if p.Port != src { + return false + } + return true +} diff --git a/kitex_gen/config/k-config.go b/kitex_gen/config/k-config.go index e653065..f60382d 100644 --- a/kitex_gen/config/k-config.go +++ b/kitex_gen/config/k-config.go @@ -23,12 +23,14 @@ var ( _ = bthrift.BinaryWriter(nil) ) -func (p *PushConfig) FastRead(buf []byte) (int, error) { +func (p *PusherConfig) FastRead(buf []byte) (int, error) { var err error var offset int var l int var fieldTypeId thrift.TType var fieldId int16 + var issetName bool = false + var issetOption bool = false _, l, err = bthrift.Binary.ReadStructBegin(buf) offset += l if err != nil { @@ -74,7 +76,794 @@ func (p *PushConfig) FastRead(buf []byte) (int, error) { } } case 3: - if fieldTypeId == thrift.BYTE { + if fieldTypeId == thrift.I32 { + l, err = p.FastReadField3(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 4: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField4(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetName = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 5: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField5(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 6: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField6(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetOption = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetName { + fieldId = 4 + goto RequiredFieldNotSetError + } + + if !issetOption { + fieldId = 6 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PusherConfig[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PusherConfig[fieldId])) +} + +func (p *PusherConfig) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Id = v + + } + return offset, nil +} + +func (p *PusherConfig) FastReadField2(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.CreatedAt = v + + } + return offset, nil +} + +func (p *PusherConfig) FastReadField3(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Type = PusherConfigType(v) + + } + return offset, nil +} + +func (p *PusherConfig) FastReadField4(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Name = v + + } + return offset, nil +} + +func (p *PusherConfig) FastReadField5(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Remark = v + + } + return offset, nil +} + +func (p *PusherConfig) FastReadField6(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Option = v + + } + return offset, nil +} + +// for compatibility +func (p *PusherConfig) FastWrite(buf []byte) int { + return 0 +} + +func (p *PusherConfig) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PusherConfig") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + offset += p.fastWriteField3(buf[offset:], binaryWriter) + offset += p.fastWriteField4(buf[offset:], binaryWriter) + offset += p.fastWriteField5(buf[offset:], binaryWriter) + offset += p.fastWriteField6(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("PusherConfig") + if p != nil { + l += p.field1Length() + l += p.field2Length() + l += p.field3Length() + l += p.field4Length() + l += p.field5Length() + l += p.field6Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *PusherConfig) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "id", thrift.I64, 1) + offset += bthrift.Binary.WriteI64(buf[offset:], p.Id) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "createdAt", thrift.I64, 2) + offset += bthrift.Binary.WriteI64(buf[offset:], p.CreatedAt) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "type", thrift.I32, 3) + offset += bthrift.Binary.WriteI32(buf[offset:], int32(p.Type)) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "name", thrift.STRING, 4) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Name) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) fastWriteField5(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "remark", thrift.STRING, 5) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Remark) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) fastWriteField6(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "option", thrift.STRING, 6) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Option) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *PusherConfig) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("id", thrift.I64, 1) + l += bthrift.Binary.I64Length(p.Id) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *PusherConfig) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("createdAt", thrift.I64, 2) + l += bthrift.Binary.I64Length(p.CreatedAt) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *PusherConfig) field3Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("type", thrift.I32, 3) + l += bthrift.Binary.I32Length(int32(p.Type)) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *PusherConfig) field4Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("name", thrift.STRING, 4) + l += bthrift.Binary.StringLengthNocopy(p.Name) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *PusherConfig) field5Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("remark", thrift.STRING, 5) + l += bthrift.Binary.StringLengthNocopy(p.Remark) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *PusherConfig) field6Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("option", thrift.STRING, 6) + l += bthrift.Binary.StringLengthNocopy(p.Option) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *FormItem) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.BOOL { + l, err = p.FastReadField3(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_FormItem[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *FormItem) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Param = v + + } + return offset, nil +} + +func (p *FormItem) FastReadField2(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Type = v + + } + return offset, nil +} + +func (p *FormItem) FastReadField3(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadBool(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Require = v + + } + return offset, nil +} + +// for compatibility +func (p *FormItem) FastWrite(buf []byte) int { + return 0 +} + +func (p *FormItem) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "FormItem") + if p != nil { + offset += p.fastWriteField3(buf[offset:], binaryWriter) + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *FormItem) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("FormItem") + if p != nil { + l += p.field1Length() + l += p.field2Length() + l += p.field3Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *FormItem) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "param", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Param) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *FormItem) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "type", thrift.STRING, 2) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Type) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *FormItem) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "require", thrift.BOOL, 3) + offset += bthrift.Binary.WriteBool(buf[offset:], p.Require) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *FormItem) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("param", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Param) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *FormItem) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("type", thrift.STRING, 2) + l += bthrift.Binary.StringLengthNocopy(p.Type) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *FormItem) field3Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("require", thrift.BOOL, 3) + l += bthrift.Binary.BoolLength(p.Require) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *AnPush) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AnPush[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *AnPush) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Token = v + + } + return offset, nil +} + +func (p *AnPush) FastReadField2(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Channel = v + + } + return offset, nil +} + +// for compatibility +func (p *AnPush) FastWrite(buf []byte) int { + return 0 +} + +func (p *AnPush) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "AnPush") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *AnPush) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("AnPush") + if p != nil { + l += p.field1Length() + l += p.field2Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *AnPush) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "token", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Token) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *AnPush) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "channel", thrift.STRING, 2) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Channel) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *AnPush) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("token", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Token) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *AnPush) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("channel", thrift.STRING, 2) + l += bthrift.Binary.StringLengthNocopy(p.Channel) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EmailPush) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRING { l, err = p.FastReadField3(buf[offset:]) offset += l if err != nil { @@ -116,7 +905,7 @@ func (p *PushConfig) FastRead(buf []byte) (int, error) { } } case 6: - if fieldTypeId == thrift.STRING { + if fieldTypeId == thrift.I32 { l, err = p.FastReadField6(buf[offset:]) offset += l if err != nil { @@ -155,7 +944,7 @@ ReadStructBeginError: ReadFieldBeginError: return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) ReadFieldError: - return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushConfig[fieldId]), err) + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EmailPush[fieldId]), err) SkipFieldError: return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) ReadFieldEndError: @@ -164,49 +953,7 @@ ReadStructEndError: return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) } -func (p *PushConfig) FastReadField1(buf []byte) (int, error) { - offset := 0 - - if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { - return offset, err - } else { - offset += l - - p.Id = v - - } - return offset, nil -} - -func (p *PushConfig) FastReadField2(buf []byte) (int, error) { - offset := 0 - - if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { - return offset, err - } else { - offset += l - - p.CreatedAt = v - - } - return offset, nil -} - -func (p *PushConfig) FastReadField3(buf []byte) (int, error) { - offset := 0 - - if v, l, err := bthrift.Binary.ReadByte(buf[offset:]); err != nil { - return offset, err - } else { - offset += l - - p.Type = v - - } - return offset, nil -} - -func (p *PushConfig) FastReadField4(buf []byte) (int, error) { +func (p *EmailPush) FastReadField1(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { @@ -214,13 +961,13 @@ func (p *PushConfig) FastReadField4(buf []byte) (int, error) { } else { offset += l - p.Name = v + p.From = v } return offset, nil } -func (p *PushConfig) FastReadField5(buf []byte) (int, error) { +func (p *EmailPush) FastReadField2(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { @@ -228,13 +975,13 @@ func (p *PushConfig) FastReadField5(buf []byte) (int, error) { } else { offset += l - p.Remark = v + p.To = v } return offset, nil } -func (p *PushConfig) FastReadField6(buf []byte) (int, error) { +func (p *EmailPush) FastReadField3(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { @@ -242,36 +989,78 @@ func (p *PushConfig) FastReadField6(buf []byte) (int, error) { } else { offset += l - p.Option = v + p.Username = v + + } + return offset, nil +} + +func (p *EmailPush) FastReadField4(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Password = v + + } + return offset, nil +} + +func (p *EmailPush) FastReadField5(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Host = v + + } + return offset, nil +} + +func (p *EmailPush) FastReadField6(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Port = v } return offset, nil } // for compatibility -func (p *PushConfig) FastWrite(buf []byte) int { +func (p *EmailPush) FastWrite(buf []byte) int { return 0 } -func (p *PushConfig) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PushConfig") + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EmailPush") if p != nil { + offset += p.fastWriteField6(buf[offset:], binaryWriter) offset += p.fastWriteField1(buf[offset:], binaryWriter) offset += p.fastWriteField2(buf[offset:], binaryWriter) offset += p.fastWriteField3(buf[offset:], binaryWriter) offset += p.fastWriteField4(buf[offset:], binaryWriter) offset += p.fastWriteField5(buf[offset:], binaryWriter) - offset += p.fastWriteField6(buf[offset:], binaryWriter) } offset += bthrift.Binary.WriteFieldStop(buf[offset:]) offset += bthrift.Binary.WriteStructEnd(buf[offset:]) return offset } -func (p *PushConfig) BLength() int { +func (p *EmailPush) BLength() int { l := 0 - l += bthrift.Binary.StructBeginLength("PushConfig") + l += bthrift.Binary.StructBeginLength("EmailPush") if p != nil { l += p.field1Length() l += p.field2Length() @@ -285,109 +1074,109 @@ func (p *PushConfig) BLength() int { return l } -func (p *PushConfig) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "id", thrift.I64, 1) - offset += bthrift.Binary.WriteI64(buf[offset:], p.Id) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "from", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.From) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "createdAt", thrift.I64, 2) - offset += bthrift.Binary.WriteI64(buf[offset:], p.CreatedAt) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "to", thrift.STRING, 2) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.To) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "type", thrift.BYTE, 3) - offset += bthrift.Binary.WriteByte(buf[offset:], p.Type) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "username", thrift.STRING, 3) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Username) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "name", thrift.STRING, 4) - offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Name) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "password", thrift.STRING, 4) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Password) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) fastWriteField5(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField5(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "remark", thrift.STRING, 5) - offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Remark) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "host", thrift.STRING, 5) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Host) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) fastWriteField6(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *EmailPush) fastWriteField6(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "option", thrift.STRING, 6) - offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Option) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "port", thrift.I32, 6) + offset += bthrift.Binary.WriteI32(buf[offset:], p.Port) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushConfig) field1Length() int { +func (p *EmailPush) field1Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("id", thrift.I64, 1) - l += bthrift.Binary.I64Length(p.Id) + l += bthrift.Binary.FieldBeginLength("from", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.From) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushConfig) field2Length() int { +func (p *EmailPush) field2Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("createdAt", thrift.I64, 2) - l += bthrift.Binary.I64Length(p.CreatedAt) + l += bthrift.Binary.FieldBeginLength("to", thrift.STRING, 2) + l += bthrift.Binary.StringLengthNocopy(p.To) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushConfig) field3Length() int { +func (p *EmailPush) field3Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("type", thrift.BYTE, 3) - l += bthrift.Binary.ByteLength(p.Type) + l += bthrift.Binary.FieldBeginLength("username", thrift.STRING, 3) + l += bthrift.Binary.StringLengthNocopy(p.Username) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushConfig) field4Length() int { +func (p *EmailPush) field4Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("name", thrift.STRING, 4) - l += bthrift.Binary.StringLengthNocopy(p.Name) + l += bthrift.Binary.FieldBeginLength("password", thrift.STRING, 4) + l += bthrift.Binary.StringLengthNocopy(p.Password) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushConfig) field5Length() int { +func (p *EmailPush) field5Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("remark", thrift.STRING, 5) - l += bthrift.Binary.StringLengthNocopy(p.Remark) + l += bthrift.Binary.FieldBeginLength("host", thrift.STRING, 5) + l += bthrift.Binary.StringLengthNocopy(p.Host) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushConfig) field6Length() int { +func (p *EmailPush) field6Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("option", thrift.STRING, 6) - l += bthrift.Binary.StringLengthNocopy(p.Option) + l += bthrift.Binary.FieldBeginLength("port", thrift.I32, 6) + l += bthrift.Binary.I32Length(p.Port) l += bthrift.Binary.FieldEndLength() return l diff --git a/kitex_gen/push/k-push.go b/kitex_gen/push/k-push.go index 8eed28a..0cc436a 100644 --- a/kitex_gen/push/k-push.go +++ b/kitex_gen/push/k-push.go @@ -32,7 +32,7 @@ func (p *PushReq) FastRead(buf []byte) (int, error) { var l int var fieldTypeId thrift.TType var fieldId int16 - var issetId bool = false + var issetIds bool = false var issetTitle bool = false var issetContent bool = false _, l, err = bthrift.Binary.ReadStructBegin(buf) @@ -52,13 +52,13 @@ func (p *PushReq) FastRead(buf []byte) (int, error) { } switch fieldId { case 1: - if fieldTypeId == thrift.I64 { + if fieldTypeId == thrift.LIST { l, err = p.FastReadField1(buf[offset:]) offset += l if err != nil { goto ReadFieldError } - issetId = true + issetIds = true } else { l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) offset += l @@ -116,7 +116,7 @@ func (p *PushReq) FastRead(buf []byte) (int, error) { goto ReadStructEndError } - if !issetId { + if !issetIds { fieldId = 1 goto RequiredFieldNotSetError } @@ -150,13 +150,29 @@ RequiredFieldNotSetError: func (p *PushReq) FastReadField1(buf []byte) (int, error) { offset := 0 - if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { + _, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:]) + offset += l + if err != nil { + return offset, err + } + p.Ids = make([]int64, 0, size) + for i := 0; i < size; i++ { + var _elem int64 + if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + _elem = v + + } + + p.Ids = append(p.Ids, _elem) + } + if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil { return offset, err } else { offset += l - - p.Id = v - } return offset, nil } @@ -222,9 +238,17 @@ func (p *PushReq) BLength() int { func (p *PushReq) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "id", thrift.I64, 1) - offset += bthrift.Binary.WriteI64(buf[offset:], p.Id) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "ids", thrift.LIST, 1) + listBeginOffset := offset + offset += bthrift.Binary.ListBeginLength(thrift.I64, 0) + var length int + for _, v := range p.Ids { + length++ + offset += bthrift.Binary.WriteI64(buf[offset:], v) + } + bthrift.Binary.WriteListBegin(buf[listBeginOffset:], thrift.I64, length) + offset += bthrift.Binary.WriteListEnd(buf[offset:]) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } @@ -249,9 +273,11 @@ func (p *PushReq) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) func (p *PushReq) field1Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("id", thrift.I64, 1) - l += bthrift.Binary.I64Length(p.Id) - + l += bthrift.Binary.FieldBeginLength("ids", thrift.LIST, 1) + l += bthrift.Binary.ListBeginLength(thrift.I64, len(p.Ids)) + var tmpV int64 + l += bthrift.Binary.I64Length(int64(tmpV)) * len(p.Ids) + l += bthrift.Binary.ListEndLength() l += bthrift.Binary.FieldEndLength() return l } @@ -274,13 +300,13 @@ func (p *PushReq) field3Length() int { return l } -func (p *PushResp) FastRead(buf []byte) (int, error) { +func (p *Resp) FastRead(buf []byte) (int, error) { var err error var offset int var l int var fieldTypeId thrift.TType var fieldId int16 - var issetErrCode bool = false + var issetCode bool = false _, l, err = bthrift.Binary.ReadStructBegin(buf) offset += l if err != nil { @@ -304,7 +330,7 @@ func (p *PushResp) FastRead(buf []byte) (int, error) { if err != nil { goto ReadFieldError } - issetErrCode = true + issetCode = true } else { l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) offset += l @@ -360,7 +386,7 @@ func (p *PushResp) FastRead(buf []byte) (int, error) { goto ReadStructEndError } - if !issetErrCode { + if !issetCode { fieldId = 1 goto RequiredFieldNotSetError } @@ -370,7 +396,7 @@ ReadStructBeginError: ReadFieldBeginError: return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) ReadFieldError: - return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushResp[fieldId]), err) + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Resp[fieldId]), err) SkipFieldError: return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) ReadFieldEndError: @@ -378,10 +404,10 @@ ReadFieldEndError: ReadStructEndError: return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) RequiredFieldNotSetError: - return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PushResp[fieldId])) + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_Resp[fieldId])) } -func (p *PushResp) FastReadField1(buf []byte) (int, error) { +func (p *Resp) FastReadField1(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { @@ -389,13 +415,13 @@ func (p *PushResp) FastReadField1(buf []byte) (int, error) { } else { offset += l - p.ErrCode = v + p.Code = v } return offset, nil } -func (p *PushResp) FastReadField2(buf []byte) (int, error) { +func (p *Resp) FastReadField2(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { @@ -403,13 +429,13 @@ func (p *PushResp) FastReadField2(buf []byte) (int, error) { } else { offset += l - p.ErrMsg = v + p.Msg = v } return offset, nil } -func (p *PushResp) FastReadField3(buf []byte) (int, error) { +func (p *Resp) FastReadField3(buf []byte) (int, error) { offset := 0 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { @@ -424,13 +450,13 @@ func (p *PushResp) FastReadField3(buf []byte) (int, error) { } // for compatibility -func (p *PushResp) FastWrite(buf []byte) int { +func (p *Resp) FastWrite(buf []byte) int { return 0 } -func (p *PushResp) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *Resp) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PushResp") + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Resp") if p != nil { offset += p.fastWriteField1(buf[offset:], binaryWriter) offset += p.fastWriteField2(buf[offset:], binaryWriter) @@ -441,9 +467,9 @@ func (p *PushResp) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter return offset } -func (p *PushResp) BLength() int { +func (p *Resp) BLength() int { l := 0 - l += bthrift.Binary.StructBeginLength("PushResp") + l += bthrift.Binary.StructBeginLength("Resp") if p != nil { l += p.field1Length() l += p.field2Length() @@ -454,25 +480,25 @@ func (p *PushResp) BLength() int { return l } -func (p *PushResp) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *Resp) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "errCode", thrift.I64, 1) - offset += bthrift.Binary.WriteI64(buf[offset:], p.ErrCode) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "code", thrift.I64, 1) + offset += bthrift.Binary.WriteI64(buf[offset:], p.Code) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushResp) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *Resp) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 - offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "errMsg", thrift.STRING, 2) - offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.ErrMsg) + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "msg", thrift.STRING, 2) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) return offset } -func (p *PushResp) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { +func (p *Resp) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { offset := 0 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "msgId", thrift.STRING, 3) offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.MsgId) @@ -481,25 +507,25 @@ func (p *PushResp) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter return offset } -func (p *PushResp) field1Length() int { +func (p *Resp) field1Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("errCode", thrift.I64, 1) - l += bthrift.Binary.I64Length(p.ErrCode) + l += bthrift.Binary.FieldBeginLength("code", thrift.I64, 1) + l += bthrift.Binary.I64Length(p.Code) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushResp) field2Length() int { +func (p *Resp) field2Length() int { l := 0 - l += bthrift.Binary.FieldBeginLength("errMsg", thrift.STRING, 2) - l += bthrift.Binary.StringLengthNocopy(p.ErrMsg) + l += bthrift.Binary.FieldBeginLength("msg", thrift.STRING, 2) + l += bthrift.Binary.StringLengthNocopy(p.Msg) l += bthrift.Binary.FieldEndLength() return l } -func (p *PushResp) field3Length() int { +func (p *Resp) field3Length() int { l := 0 l += bthrift.Binary.FieldBeginLength("msgId", thrift.STRING, 3) l += bthrift.Binary.StringLengthNocopy(p.MsgId) @@ -897,9 +923,9 @@ func (p *ListPusherResponse) FastReadField2(buf []byte) (int, error) { if err != nil { return offset, err } - p.List = make([]*config.PushConfig, 0, size) + p.List = make([]*config.PusherConfig, 0, size) for i := 0; i < size; i++ { - _elem := config.NewPushConfig() + _elem := config.NewPusherConfig() if l, err := _elem.FastRead(buf[offset:]); err != nil { return offset, err } else { @@ -991,6 +1017,202 @@ func (p *ListPusherResponse) field2Length() int { return l } +func (p *GetPusherOptionsResponse) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.MAP { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_GetPusherOptionsResponse[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *GetPusherOptionsResponse) FastReadField1(buf []byte) (int, error) { + offset := 0 + + _, _, size, l, err := bthrift.Binary.ReadMapBegin(buf[offset:]) + offset += l + if err != nil { + return offset, err + } + p.Options = make(map[config.PusherConfigType][]*config.FormItem, size) + for i := 0; i < size; i++ { + var _key config.PusherConfigType + if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + _key = config.PusherConfigType(v) + + } + + _, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:]) + offset += l + if err != nil { + return offset, err + } + _val := make([]*config.FormItem, 0, size) + for i := 0; i < size; i++ { + _elem := config.NewFormItem() + if l, err := _elem.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + + _val = append(_val, _elem) + } + if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + + p.Options[_key] = _val + } + if l, err := bthrift.Binary.ReadMapEnd(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + return offset, nil +} + +// for compatibility +func (p *GetPusherOptionsResponse) FastWrite(buf []byte) int { + return 0 +} + +func (p *GetPusherOptionsResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "GetPusherOptionsResponse") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *GetPusherOptionsResponse) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("GetPusherOptionsResponse") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *GetPusherOptionsResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "options", thrift.MAP, 1) + mapBeginOffset := offset + offset += bthrift.Binary.MapBeginLength(thrift.I32, thrift.LIST, 0) + var length int + for k, v := range p.Options { + length++ + + offset += bthrift.Binary.WriteI32(buf[offset:], int32(k)) + + listBeginOffset := offset + offset += bthrift.Binary.ListBeginLength(thrift.STRUCT, 0) + var length int + for _, v := range v { + length++ + offset += v.FastWriteNocopy(buf[offset:], binaryWriter) + } + bthrift.Binary.WriteListBegin(buf[listBeginOffset:], thrift.STRUCT, length) + offset += bthrift.Binary.WriteListEnd(buf[offset:]) + } + bthrift.Binary.WriteMapBegin(buf[mapBeginOffset:], thrift.I32, thrift.LIST, length) + offset += bthrift.Binary.WriteMapEnd(buf[offset:]) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *GetPusherOptionsResponse) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("options", thrift.MAP, 1) + l += bthrift.Binary.MapBeginLength(thrift.I32, thrift.LIST, len(p.Options)) + for k, v := range p.Options { + + l += bthrift.Binary.I32Length(int32(k)) + + l += bthrift.Binary.ListBeginLength(thrift.STRUCT, len(v)) + for _, v := range v { + l += v.BLength() + } + l += bthrift.Binary.ListEndLength() + } + l += bthrift.Binary.MapEndLength() + l += bthrift.Binary.FieldEndLength() + return l +} + func (p *PushServicePushArgs) FastRead(buf []byte) (int, error) { var err error var offset int @@ -1192,7 +1414,7 @@ ReadStructEndError: func (p *PushServicePushResult) FastReadField0(buf []byte) (int, error) { offset := 0 - tmp := NewPushResp() + tmp := NewResp() if l, err := tmp.FastRead(buf[offset:]); err != nil { return offset, err } else { @@ -1323,7 +1545,7 @@ ReadStructEndError: func (p *PushServiceAddArgs) FastReadField1(buf []byte) (int, error) { offset := 0 - tmp := config.NewPushConfig() + tmp := config.NewPusherConfig() if l, err := tmp.FastRead(buf[offset:]); err != nil { return offset, err } else { @@ -1397,10 +1619,27 @@ func (p *PushServiceAddResult) FastRead(buf []byte) (int, error) { if fieldTypeId == thrift.STOP { break } - l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) - offset += l - if err != nil { - goto SkipFieldError + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } } l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) @@ -1420,6 +1659,8 @@ ReadStructBeginError: return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) ReadFieldBeginError: return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushServiceAddResult[fieldId]), err) SkipFieldError: return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) ReadFieldEndError: @@ -1428,6 +1669,19 @@ ReadStructEndError: return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) } +func (p *PushServiceAddResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewResp() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + // for compatibility func (p *PushServiceAddResult) FastWrite(buf []byte) int { return 0 @@ -1437,6 +1691,7 @@ func (p *PushServiceAddResult) FastWriteNocopy(buf []byte, binaryWriter bthrift. offset := 0 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Add_result") if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) } offset += bthrift.Binary.WriteFieldStop(buf[offset:]) offset += bthrift.Binary.WriteStructEnd(buf[offset:]) @@ -1447,12 +1702,33 @@ func (p *PushServiceAddResult) BLength() int { l := 0 l += bthrift.Binary.StructBeginLength("Add_result") if p != nil { + l += p.field0Length() } l += bthrift.Binary.FieldStopLength() l += bthrift.Binary.StructEndLength() return l } +func (p *PushServiceAddResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *PushServiceAddResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + func (p *PushServiceListArgs) FastRead(buf []byte) (int, error) { var err error var offset int @@ -1711,6 +1987,214 @@ func (p *PushServiceListResult) field0Length() int { return l } +func (p *PushServiceGetPusherOptionsArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *PushServiceGetPusherOptionsArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *PushServiceGetPusherOptionsArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "GetPusherOptions_args") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *PushServiceGetPusherOptionsArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("GetPusherOptions_args") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *PushServiceGetPusherOptionsResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushServiceGetPusherOptionsResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewGetPusherOptionsResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *PushServiceGetPusherOptionsResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *PushServiceGetPusherOptionsResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "GetPusherOptions_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *PushServiceGetPusherOptionsResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("GetPusherOptions_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *PushServiceGetPusherOptionsResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *PushServiceGetPusherOptionsResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + func (p *PushServicePushArgs) GetFirstArgument() interface{} { return p.Req } @@ -1724,7 +2208,7 @@ func (p *PushServiceAddArgs) GetFirstArgument() interface{} { } func (p *PushServiceAddResult) GetResult() interface{} { - return nil + return p.Success } func (p *PushServiceListArgs) GetFirstArgument() interface{} { @@ -1734,3 +2218,11 @@ func (p *PushServiceListArgs) GetFirstArgument() interface{} { func (p *PushServiceListResult) GetResult() interface{} { return p.Success } + +func (p *PushServiceGetPusherOptionsArgs) GetFirstArgument() interface{} { + return nil +} + +func (p *PushServiceGetPusherOptionsResult) GetResult() interface{} { + return p.Success +} diff --git a/kitex_gen/push/push.go b/kitex_gen/push/push.go index 8f254ae..ea1e17d 100644 --- a/kitex_gen/push/push.go +++ b/kitex_gen/push/push.go @@ -11,9 +11,9 @@ import ( ) type PushReq struct { - Id int64 `thrift:"id,1,required" frugal:"1,required,i64" form:"id,required" json:"id,required" query:"id,required"` - Title string `thrift:"title,2,required" frugal:"2,required,string" form:"title,required" json:"title,required" query:"title,required"` - Content string `thrift:"content,3,required" frugal:"3,required,string" form:"content,required" json:"content,required" query:"content,required"` + Ids []int64 `thrift:"ids,1,required" frugal:"1,required,list" json:"ids"` + Title string `thrift:"title,2,required" frugal:"2,required,string" json:"title"` + Content string `thrift:"content,3,required" frugal:"3,required,string" json:"content"` } func NewPushReq() *PushReq { @@ -24,8 +24,8 @@ func (p *PushReq) InitDefault() { *p = PushReq{} } -func (p *PushReq) GetId() (v int64) { - return p.Id +func (p *PushReq) GetIds() (v []int64) { + return p.Ids } func (p *PushReq) GetTitle() (v string) { @@ -35,8 +35,8 @@ func (p *PushReq) GetTitle() (v string) { func (p *PushReq) GetContent() (v string) { return p.Content } -func (p *PushReq) SetId(val int64) { - p.Id = val +func (p *PushReq) SetIds(val []int64) { + p.Ids = val } func (p *PushReq) SetTitle(val string) { p.Title = val @@ -46,7 +46,7 @@ func (p *PushReq) SetContent(val string) { } var fieldIDToName_PushReq = map[int16]string{ - 1: "id", + 1: "ids", 2: "title", 3: "content", } @@ -55,7 +55,7 @@ func (p *PushReq) Read(iprot thrift.TProtocol) (err error) { var fieldTypeId thrift.TType var fieldId int16 - var issetId bool = false + var issetIds bool = false var issetTitle bool = false var issetContent bool = false @@ -74,11 +74,11 @@ func (p *PushReq) Read(iprot thrift.TProtocol) (err error) { switch fieldId { case 1: - if fieldTypeId == thrift.I64 { + if fieldTypeId == thrift.LIST { if err = p.ReadField1(iprot); err != nil { goto ReadFieldError } - issetId = true + issetIds = true } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } @@ -113,7 +113,7 @@ func (p *PushReq) Read(iprot thrift.TProtocol) (err error) { goto ReadStructEndError } - if !issetId { + if !issetIds { fieldId = 1 goto RequiredFieldNotSetError } @@ -146,14 +146,26 @@ RequiredFieldNotSetError: } func (p *PushReq) ReadField1(iprot thrift.TProtocol) error { - - var _field int64 - if v, err := iprot.ReadI64(); err != nil { + _, size, err := iprot.ReadListBegin() + if err != nil { return err - } else { - _field = v } - p.Id = _field + _field := make([]int64, 0, size) + for i := 0; i < size; i++ { + + var _elem int64 + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + _elem = v + } + + _field = append(_field, _elem) + } + if err := iprot.ReadListEnd(); err != nil { + return err + } + p.Ids = _field return nil } func (p *PushReq) ReadField2(iprot thrift.TProtocol) error { @@ -216,10 +228,18 @@ WriteStructEndError: } func (p *PushReq) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + if err = oprot.WriteFieldBegin("ids", thrift.LIST, 1); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteI64(p.Id); err != nil { + if err := oprot.WriteListBegin(thrift.I64, len(p.Ids)); err != nil { + return err + } + for _, v := range p.Ids { + if err := oprot.WriteI64(v); err != nil { + return err + } + } + if err := oprot.WriteListEnd(); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -280,7 +300,7 @@ func (p *PushReq) DeepEqual(ano *PushReq) bool { } else if p == nil || ano == nil { return false } - if !p.Field1DeepEqual(ano.Id) { + if !p.Field1DeepEqual(ano.Ids) { return false } if !p.Field2DeepEqual(ano.Title) { @@ -292,11 +312,17 @@ func (p *PushReq) DeepEqual(ano *PushReq) bool { return true } -func (p *PushReq) Field1DeepEqual(src int64) bool { +func (p *PushReq) Field1DeepEqual(src []int64) bool { - if p.Id != src { + if len(p.Ids) != len(src) { return false } + for i, v := range p.Ids { + _src := src[i] + if v != _src { + return false + } + } return true } func (p *PushReq) Field2DeepEqual(src string) bool { @@ -314,52 +340,52 @@ func (p *PushReq) Field3DeepEqual(src string) bool { return true } -type PushResp struct { - ErrCode int64 `thrift:"errCode,1,required" frugal:"1,required,i64" form:"errCode,required" json:"errCode,required" query:"errCode,required"` - ErrMsg string `thrift:"errMsg,2" frugal:"2,default,string" form:"errMsg" json:"errMsg" query:"errMsg"` - MsgId string `thrift:"msgId,3" frugal:"3,default,string" form:"msgId" json:"msgId" query:"msgId"` +type Resp struct { + Code int64 `thrift:"code,1,required" frugal:"1,required,i64" json:"code"` + Msg string `thrift:"msg,2" frugal:"2,default,string" json:"msg"` + MsgId string `thrift:"msgId,3" frugal:"3,default,string" json:"msgId"` } -func NewPushResp() *PushResp { - return &PushResp{} +func NewResp() *Resp { + return &Resp{} } -func (p *PushResp) InitDefault() { - *p = PushResp{} +func (p *Resp) InitDefault() { + *p = Resp{} } -func (p *PushResp) GetErrCode() (v int64) { - return p.ErrCode +func (p *Resp) GetCode() (v int64) { + return p.Code } -func (p *PushResp) GetErrMsg() (v string) { - return p.ErrMsg +func (p *Resp) GetMsg() (v string) { + return p.Msg } -func (p *PushResp) GetMsgId() (v string) { +func (p *Resp) GetMsgId() (v string) { return p.MsgId } -func (p *PushResp) SetErrCode(val int64) { - p.ErrCode = val +func (p *Resp) SetCode(val int64) { + p.Code = val } -func (p *PushResp) SetErrMsg(val string) { - p.ErrMsg = val +func (p *Resp) SetMsg(val string) { + p.Msg = val } -func (p *PushResp) SetMsgId(val string) { +func (p *Resp) SetMsgId(val string) { p.MsgId = val } -var fieldIDToName_PushResp = map[int16]string{ - 1: "errCode", - 2: "errMsg", +var fieldIDToName_Resp = map[int16]string{ + 1: "code", + 2: "msg", 3: "msgId", } -func (p *PushResp) Read(iprot thrift.TProtocol) (err error) { +func (p *Resp) Read(iprot thrift.TProtocol) (err error) { var fieldTypeId thrift.TType var fieldId int16 - var issetErrCode bool = false + var issetCode bool = false if _, err = iprot.ReadStructBegin(); err != nil { goto ReadStructBeginError @@ -380,7 +406,7 @@ func (p *PushResp) Read(iprot thrift.TProtocol) (err error) { if err = p.ReadField1(iprot); err != nil { goto ReadFieldError } - issetErrCode = true + issetCode = true } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } @@ -413,7 +439,7 @@ func (p *PushResp) Read(iprot thrift.TProtocol) (err error) { goto ReadStructEndError } - if !issetErrCode { + if !issetCode { fieldId = 1 goto RequiredFieldNotSetError } @@ -423,7 +449,7 @@ ReadStructBeginError: ReadFieldBeginError: return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushResp[fieldId]), err) + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Resp[fieldId]), err) SkipFieldError: return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) @@ -432,10 +458,10 @@ ReadFieldEndError: ReadStructEndError: return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) RequiredFieldNotSetError: - return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PushResp[fieldId])) + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_Resp[fieldId])) } -func (p *PushResp) ReadField1(iprot thrift.TProtocol) error { +func (p *Resp) ReadField1(iprot thrift.TProtocol) error { var _field int64 if v, err := iprot.ReadI64(); err != nil { @@ -443,10 +469,10 @@ func (p *PushResp) ReadField1(iprot thrift.TProtocol) error { } else { _field = v } - p.ErrCode = _field + p.Code = _field return nil } -func (p *PushResp) ReadField2(iprot thrift.TProtocol) error { +func (p *Resp) ReadField2(iprot thrift.TProtocol) error { var _field string if v, err := iprot.ReadString(); err != nil { @@ -454,10 +480,10 @@ func (p *PushResp) ReadField2(iprot thrift.TProtocol) error { } else { _field = v } - p.ErrMsg = _field + p.Msg = _field return nil } -func (p *PushResp) ReadField3(iprot thrift.TProtocol) error { +func (p *Resp) ReadField3(iprot thrift.TProtocol) error { var _field string if v, err := iprot.ReadString(); err != nil { @@ -469,9 +495,9 @@ func (p *PushResp) ReadField3(iprot thrift.TProtocol) error { return nil } -func (p *PushResp) Write(oprot thrift.TProtocol) (err error) { +func (p *Resp) Write(oprot thrift.TProtocol) (err error) { var fieldId int16 - if err = oprot.WriteStructBegin("PushResp"); err != nil { + if err = oprot.WriteStructBegin("Resp"); err != nil { goto WriteStructBeginError } if p != nil { @@ -505,11 +531,11 @@ WriteStructEndError: return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) } -func (p *PushResp) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("errCode", thrift.I64, 1); err != nil { +func (p *Resp) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I64, 1); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteI64(p.ErrCode); err != nil { + if err := oprot.WriteI64(p.Code); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -522,11 +548,11 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) } -func (p *PushResp) writeField2(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("errMsg", thrift.STRING, 2); err != nil { +func (p *Resp) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteString(p.ErrMsg); err != nil { + if err := oprot.WriteString(p.Msg); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -539,7 +565,7 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) } -func (p *PushResp) writeField3(oprot thrift.TProtocol) (err error) { +func (p *Resp) writeField3(oprot thrift.TProtocol) (err error) { if err = oprot.WriteFieldBegin("msgId", thrift.STRING, 3); err != nil { goto WriteFieldBeginError } @@ -556,24 +582,24 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) } -func (p *PushResp) String() string { +func (p *Resp) String() string { if p == nil { return "" } - return fmt.Sprintf("PushResp(%+v)", *p) + return fmt.Sprintf("Resp(%+v)", *p) } -func (p *PushResp) DeepEqual(ano *PushResp) bool { +func (p *Resp) DeepEqual(ano *Resp) bool { if p == ano { return true } else if p == nil || ano == nil { return false } - if !p.Field1DeepEqual(ano.ErrCode) { + if !p.Field1DeepEqual(ano.Code) { return false } - if !p.Field2DeepEqual(ano.ErrMsg) { + if !p.Field2DeepEqual(ano.Msg) { return false } if !p.Field3DeepEqual(ano.MsgId) { @@ -582,21 +608,21 @@ func (p *PushResp) DeepEqual(ano *PushResp) bool { return true } -func (p *PushResp) Field1DeepEqual(src int64) bool { +func (p *Resp) Field1DeepEqual(src int64) bool { - if p.ErrCode != src { + if p.Code != src { return false } return true } -func (p *PushResp) Field2DeepEqual(src string) bool { +func (p *Resp) Field2DeepEqual(src string) bool { - if strings.Compare(p.ErrMsg, src) != 0 { + if strings.Compare(p.Msg, src) != 0 { return false } return true } -func (p *PushResp) Field3DeepEqual(src string) bool { +func (p *Resp) Field3DeepEqual(src string) bool { if strings.Compare(p.MsgId, src) != 0 { return false @@ -605,10 +631,10 @@ func (p *PushResp) Field3DeepEqual(src string) bool { } type ListPusherRequest struct { - Keyword string `thrift:"keyword,1" frugal:"1,default,string" form:"keyword" json:"keyword" query:"keyword"` - Page int64 `thrift:"page,2,optional" frugal:"2,optional,i64" form:"page" json:"page,omitempty" query:"page"` - Size int16 `thrift:"size,3,optional" frugal:"3,optional,i16" form:"size" json:"size,omitempty" query:"size"` - All bool `thrift:"all,4" frugal:"4,default,bool" form:"all" json:"all" query:"all"` + Keyword string `thrift:"keyword,1" frugal:"1,default,string" json:"keyword"` + Page int64 `thrift:"page,2,optional" frugal:"2,optional,i64" json:"page,omitempty"` + Size int16 `thrift:"size,3,optional" frugal:"3,optional,i16" json:"size,omitempty"` + All bool `thrift:"all,4" frugal:"4,default,bool" json:"all"` } func NewListPusherRequest() *ListPusherRequest { @@ -976,8 +1002,8 @@ func (p *ListPusherRequest) Field4DeepEqual(src bool) bool { } type ListPusherResponse struct { - Total int64 `thrift:"total,1" frugal:"1,default,i64" form:"total" json:"total" query:"total"` - List []*config.PushConfig `thrift:"list,2" frugal:"2,default,list" form:"list" json:"list" query:"list"` + Total int64 `thrift:"total,1" frugal:"1,default,i64" json:"total"` + List []*config.PusherConfig `thrift:"list,2" frugal:"2,default,list" json:"list"` } func NewListPusherResponse() *ListPusherResponse { @@ -992,13 +1018,13 @@ func (p *ListPusherResponse) GetTotal() (v int64) { return p.Total } -func (p *ListPusherResponse) GetList() (v []*config.PushConfig) { +func (p *ListPusherResponse) GetList() (v []*config.PusherConfig) { return p.List } func (p *ListPusherResponse) SetTotal(val int64) { p.Total = val } -func (p *ListPusherResponse) SetList(val []*config.PushConfig) { +func (p *ListPusherResponse) SetList(val []*config.PusherConfig) { p.List = val } @@ -1087,8 +1113,8 @@ func (p *ListPusherResponse) ReadField2(iprot thrift.TProtocol) error { if err != nil { return err } - _field := make([]*config.PushConfig, 0, size) - values := make([]config.PushConfig, size) + _field := make([]*config.PusherConfig, 0, size) + values := make([]config.PusherConfig, size) for i := 0; i < size; i++ { _elem := &values[i] @@ -1209,7 +1235,7 @@ func (p *ListPusherResponse) Field1DeepEqual(src int64) bool { } return true } -func (p *ListPusherResponse) Field2DeepEqual(src []*config.PushConfig) bool { +func (p *ListPusherResponse) Field2DeepEqual(src []*config.PusherConfig) bool { if len(p.List) != len(src) { return false @@ -1223,12 +1249,238 @@ func (p *ListPusherResponse) Field2DeepEqual(src []*config.PushConfig) bool { return true } -type PushService interface { - Push(ctx context.Context, req *PushReq) (r *PushResp, err error) +type GetPusherOptionsResponse struct { + Options map[config.PusherConfigType][]*config.FormItem `thrift:"options,1" frugal:"1,default,map>" json:"options"` +} - Add(ctx context.Context, req *config.PushConfig) (err error) +func NewGetPusherOptionsResponse() *GetPusherOptionsResponse { + return &GetPusherOptionsResponse{} +} + +func (p *GetPusherOptionsResponse) InitDefault() { + *p = GetPusherOptionsResponse{} +} + +func (p *GetPusherOptionsResponse) GetOptions() (v map[config.PusherConfigType][]*config.FormItem) { + return p.Options +} +func (p *GetPusherOptionsResponse) SetOptions(val map[config.PusherConfigType][]*config.FormItem) { + p.Options = val +} + +var fieldIDToName_GetPusherOptionsResponse = map[int16]string{ + 1: "options", +} + +func (p *GetPusherOptionsResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.MAP { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_GetPusherOptionsResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *GetPusherOptionsResponse) ReadField1(iprot thrift.TProtocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return err + } + _field := make(map[config.PusherConfigType][]*config.FormItem, size) + for i := 0; i < size; i++ { + var _key config.PusherConfigType + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + _key = config.PusherConfigType(v) + } + _, size, err := iprot.ReadListBegin() + if err != nil { + return err + } + _val := make([]*config.FormItem, 0, size) + values := make([]config.FormItem, size) + for i := 0; i < size; i++ { + _elem := &values[i] + + if err := _elem.Read(iprot); err != nil { + return err + } + + _val = append(_val, _elem) + } + if err := iprot.ReadListEnd(); err != nil { + return err + } + + _field[_key] = _val + } + if err := iprot.ReadMapEnd(); err != nil { + return err + } + p.Options = _field + return nil +} + +func (p *GetPusherOptionsResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("GetPusherOptionsResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *GetPusherOptionsResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("options", thrift.MAP, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteMapBegin(thrift.I32, thrift.LIST, len(p.Options)); err != nil { + return err + } + for k, v := range p.Options { + if err := oprot.WriteI32(int32(k)); err != nil { + return err + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(v)); err != nil { + return err + } + for _, v := range v { + if err := v.Write(oprot); err != nil { + return err + } + } + if err := oprot.WriteListEnd(); err != nil { + return err + } + } + if err := oprot.WriteMapEnd(); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *GetPusherOptionsResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetPusherOptionsResponse(%+v)", *p) + +} + +func (p *GetPusherOptionsResponse) DeepEqual(ano *GetPusherOptionsResponse) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Options) { + return false + } + return true +} + +func (p *GetPusherOptionsResponse) Field1DeepEqual(src map[config.PusherConfigType][]*config.FormItem) bool { + + if len(p.Options) != len(src) { + return false + } + for k, v := range p.Options { + _src := src[k] + if len(v) != len(_src) { + return false + } + for i, v := range v { + _src1 := _src[i] + if !v.DeepEqual(_src1) { + return false + } + } + } + return true +} + +type PushService interface { + Push(ctx context.Context, req *PushReq) (r *Resp, err error) + + Add(ctx context.Context, req *config.PusherConfig) (r *Resp, err error) List(ctx context.Context, req *ListPusherRequest) (r *ListPusherResponse, err error) + + GetPusherOptions(ctx context.Context) (r *GetPusherOptionsResponse, err error) } type PushServiceClient struct { @@ -1257,7 +1509,7 @@ func (p *PushServiceClient) Client_() thrift.TClient { return p.c } -func (p *PushServiceClient) Push(ctx context.Context, req *PushReq) (r *PushResp, err error) { +func (p *PushServiceClient) Push(ctx context.Context, req *PushReq) (r *Resp, err error) { var _args PushServicePushArgs _args.Req = req var _result PushServicePushResult @@ -1266,14 +1518,14 @@ func (p *PushServiceClient) Push(ctx context.Context, req *PushReq) (r *PushResp } return _result.GetSuccess(), nil } -func (p *PushServiceClient) Add(ctx context.Context, req *config.PushConfig) (err error) { +func (p *PushServiceClient) Add(ctx context.Context, req *config.PusherConfig) (r *Resp, err error) { var _args PushServiceAddArgs _args.Req = req var _result PushServiceAddResult if err = p.Client_().Call(ctx, "Add", &_args, &_result); err != nil { return } - return nil + return _result.GetSuccess(), nil } func (p *PushServiceClient) List(ctx context.Context, req *ListPusherRequest) (r *ListPusherResponse, err error) { var _args PushServiceListArgs @@ -1284,6 +1536,14 @@ func (p *PushServiceClient) List(ctx context.Context, req *ListPusherRequest) (r } return _result.GetSuccess(), nil } +func (p *PushServiceClient) GetPusherOptions(ctx context.Context) (r *GetPusherOptionsResponse, err error) { + var _args PushServiceGetPusherOptionsArgs + var _result PushServiceGetPusherOptionsResult + if err = p.Client_().Call(ctx, "GetPusherOptions", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} type PushServiceProcessor struct { processorMap map[string]thrift.TProcessorFunction @@ -1308,6 +1568,7 @@ func NewPushServiceProcessor(handler PushService) *PushServiceProcessor { self.AddToProcessorMap("Push", &pushServiceProcessorPush{handler: handler}) self.AddToProcessorMap("Add", &pushServiceProcessorAdd{handler: handler}) self.AddToProcessorMap("List", &pushServiceProcessorList{handler: handler}) + self.AddToProcessorMap("GetPusherOptions", &pushServiceProcessorGetPusherOptions{handler: handler}) return self } func (p *PushServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { @@ -1347,7 +1608,7 @@ func (p *pushServiceProcessorPush) Process(ctx context.Context, seqId int32, ipr iprot.ReadMessageEnd() var err2 error result := PushServicePushResult{} - var retval *PushResp + var retval *Resp if retval, err2 = p.handler.Push(ctx, args.Req); err2 != nil { x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Push: "+err2.Error()) oprot.WriteMessageBegin("Push", thrift.EXCEPTION, seqId) @@ -1395,13 +1656,16 @@ func (p *pushServiceProcessorAdd) Process(ctx context.Context, seqId int32, ipro iprot.ReadMessageEnd() var err2 error result := PushServiceAddResult{} - if err2 = p.handler.Add(ctx, args.Req); err2 != nil { + var retval *Resp + if retval, err2 = p.handler.Add(ctx, args.Req); err2 != nil { x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Add: "+err2.Error()) oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) x.Write(oprot) oprot.WriteMessageEnd() oprot.Flush(ctx) return true, err2 + } else { + result.Success = retval } if err2 = oprot.WriteMessageBegin("Add", thrift.REPLY, seqId); err2 != nil { err = err2 @@ -1469,8 +1733,56 @@ func (p *pushServiceProcessorList) Process(ctx context.Context, seqId int32, ipr return true, err } +type pushServiceProcessorGetPusherOptions struct { + handler PushService +} + +func (p *pushServiceProcessorGetPusherOptions) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := PushServiceGetPusherOptionsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("GetPusherOptions", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := PushServiceGetPusherOptionsResult{} + var retval *GetPusherOptionsResponse + if retval, err2 = p.handler.GetPusherOptions(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing GetPusherOptions: "+err2.Error()) + oprot.WriteMessageBegin("GetPusherOptions", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("GetPusherOptions", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + type PushServicePushArgs struct { - Req *PushReq `thrift:"req,1" frugal:"1,default,PushReq"` + Req *PushReq `thrift:"req,1" frugal:"1,default,PushReq" json:"req"` } func NewPushServicePushArgs() *PushServicePushArgs { @@ -1640,7 +1952,7 @@ func (p *PushServicePushArgs) Field1DeepEqual(src *PushReq) bool { } type PushServicePushResult struct { - Success *PushResp `thrift:"success,0,optional" frugal:"0,optional,PushResp"` + Success *Resp `thrift:"success,0,optional" frugal:"0,optional,Resp" json:"success,omitempty"` } func NewPushServicePushResult() *PushServicePushResult { @@ -1651,16 +1963,16 @@ func (p *PushServicePushResult) InitDefault() { *p = PushServicePushResult{} } -var PushServicePushResult_Success_DEFAULT *PushResp +var PushServicePushResult_Success_DEFAULT *Resp -func (p *PushServicePushResult) GetSuccess() (v *PushResp) { +func (p *PushServicePushResult) GetSuccess() (v *Resp) { if !p.IsSetSuccess() { return PushServicePushResult_Success_DEFAULT } return p.Success } func (p *PushServicePushResult) SetSuccess(x interface{}) { - p.Success = x.(*PushResp) + p.Success = x.(*Resp) } var fieldIDToName_PushServicePushResult = map[int16]string{ @@ -1728,7 +2040,7 @@ ReadStructEndError: } func (p *PushServicePushResult) ReadField0(iprot thrift.TProtocol) error { - _field := NewPushResp() + _field := NewResp() if err := _field.Read(iprot); err != nil { return err } @@ -1803,7 +2115,7 @@ func (p *PushServicePushResult) DeepEqual(ano *PushServicePushResult) bool { return true } -func (p *PushServicePushResult) Field0DeepEqual(src *PushResp) bool { +func (p *PushServicePushResult) Field0DeepEqual(src *Resp) bool { if !p.Success.DeepEqual(src) { return false @@ -1812,7 +2124,7 @@ func (p *PushServicePushResult) Field0DeepEqual(src *PushResp) bool { } type PushServiceAddArgs struct { - Req *config.PushConfig `thrift:"req,1" frugal:"1,default,config.PushConfig"` + Req *config.PusherConfig `thrift:"req,1" frugal:"1,default,config.PusherConfig" json:"req"` } func NewPushServiceAddArgs() *PushServiceAddArgs { @@ -1823,15 +2135,15 @@ func (p *PushServiceAddArgs) InitDefault() { *p = PushServiceAddArgs{} } -var PushServiceAddArgs_Req_DEFAULT *config.PushConfig +var PushServiceAddArgs_Req_DEFAULT *config.PusherConfig -func (p *PushServiceAddArgs) GetReq() (v *config.PushConfig) { +func (p *PushServiceAddArgs) GetReq() (v *config.PusherConfig) { if !p.IsSetReq() { return PushServiceAddArgs_Req_DEFAULT } return p.Req } -func (p *PushServiceAddArgs) SetReq(val *config.PushConfig) { +func (p *PushServiceAddArgs) SetReq(val *config.PusherConfig) { p.Req = val } @@ -1900,7 +2212,7 @@ ReadStructEndError: } func (p *PushServiceAddArgs) ReadField1(iprot thrift.TProtocol) error { - _field := config.NewPushConfig() + _field := config.NewPusherConfig() if err := _field.Read(iprot); err != nil { return err } @@ -1973,7 +2285,7 @@ func (p *PushServiceAddArgs) DeepEqual(ano *PushServiceAddArgs) bool { return true } -func (p *PushServiceAddArgs) Field1DeepEqual(src *config.PushConfig) bool { +func (p *PushServiceAddArgs) Field1DeepEqual(src *config.PusherConfig) bool { if !p.Req.DeepEqual(src) { return false @@ -1982,6 +2294,7 @@ func (p *PushServiceAddArgs) Field1DeepEqual(src *config.PushConfig) bool { } type PushServiceAddResult struct { + Success *Resp `thrift:"success,0,optional" frugal:"0,optional,Resp" json:"success,omitempty"` } func NewPushServiceAddResult() *PushServiceAddResult { @@ -1992,7 +2305,25 @@ func (p *PushServiceAddResult) InitDefault() { *p = PushServiceAddResult{} } -var fieldIDToName_PushServiceAddResult = map[int16]string{} +var PushServiceAddResult_Success_DEFAULT *Resp + +func (p *PushServiceAddResult) GetSuccess() (v *Resp) { + if !p.IsSetSuccess() { + return PushServiceAddResult_Success_DEFAULT + } + return p.Success +} +func (p *PushServiceAddResult) SetSuccess(x interface{}) { + p.Success = x.(*Resp) +} + +var fieldIDToName_PushServiceAddResult = map[int16]string{ + 0: "success", +} + +func (p *PushServiceAddResult) IsSetSuccess() bool { + return p.Success != nil +} func (p *PushServiceAddResult) Read(iprot thrift.TProtocol) (err error) { @@ -2011,8 +2342,20 @@ func (p *PushServiceAddResult) Read(iprot thrift.TProtocol) (err error) { if fieldTypeId == thrift.STOP { break } - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldTypeError + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } } if err = iprot.ReadFieldEnd(); err != nil { goto ReadFieldEndError @@ -2027,8 +2370,10 @@ ReadStructBeginError: return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) ReadFieldBeginError: return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -SkipFieldTypeError: - return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushServiceAddResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) ReadFieldEndError: return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) @@ -2036,11 +2381,25 @@ ReadStructEndError: return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) } +func (p *PushServiceAddResult) ReadField0(iprot thrift.TProtocol) error { + _field := NewResp() + if err := _field.Read(iprot); err != nil { + return err + } + p.Success = _field + return nil +} + func (p *PushServiceAddResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 if err = oprot.WriteStructBegin("Add_result"); err != nil { goto WriteStructBeginError } if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } } if err = oprot.WriteFieldStop(); err != nil { goto WriteFieldStopError @@ -2051,12 +2410,33 @@ func (p *PushServiceAddResult) Write(oprot thrift.TProtocol) (err error) { return nil WriteStructBeginError: return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) WriteFieldStopError: return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) WriteStructEndError: return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) } +func (p *PushServiceAddResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + func (p *PushServiceAddResult) String() string { if p == nil { return "" @@ -2071,11 +2451,22 @@ func (p *PushServiceAddResult) DeepEqual(ano *PushServiceAddResult) bool { } else if p == nil || ano == nil { return false } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *PushServiceAddResult) Field0DeepEqual(src *Resp) bool { + + if !p.Success.DeepEqual(src) { + return false + } return true } type PushServiceListArgs struct { - Req *ListPusherRequest `thrift:"req,1" frugal:"1,default,ListPusherRequest"` + Req *ListPusherRequest `thrift:"req,1" frugal:"1,default,ListPusherRequest" json:"req"` } func NewPushServiceListArgs() *PushServiceListArgs { @@ -2245,7 +2636,7 @@ func (p *PushServiceListArgs) Field1DeepEqual(src *ListPusherRequest) bool { } type PushServiceListResult struct { - Success *ListPusherResponse `thrift:"success,0,optional" frugal:"0,optional,ListPusherResponse"` + Success *ListPusherResponse `thrift:"success,0,optional" frugal:"0,optional,ListPusherResponse" json:"success,omitempty"` } func NewPushServiceListResult() *PushServiceListResult { @@ -2415,3 +2806,268 @@ func (p *PushServiceListResult) Field0DeepEqual(src *ListPusherResponse) bool { } return true } + +type PushServiceGetPusherOptionsArgs struct { +} + +func NewPushServiceGetPusherOptionsArgs() *PushServiceGetPusherOptionsArgs { + return &PushServiceGetPusherOptionsArgs{} +} + +func (p *PushServiceGetPusherOptionsArgs) InitDefault() { + *p = PushServiceGetPusherOptionsArgs{} +} + +var fieldIDToName_PushServiceGetPusherOptionsArgs = map[int16]string{} + +func (p *PushServiceGetPusherOptionsArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("GetPusherOptions_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PushServiceGetPusherOptionsArgs(%+v)", *p) + +} + +func (p *PushServiceGetPusherOptionsArgs) DeepEqual(ano *PushServiceGetPusherOptionsArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type PushServiceGetPusherOptionsResult struct { + Success *GetPusherOptionsResponse `thrift:"success,0,optional" frugal:"0,optional,GetPusherOptionsResponse" json:"success,omitempty"` +} + +func NewPushServiceGetPusherOptionsResult() *PushServiceGetPusherOptionsResult { + return &PushServiceGetPusherOptionsResult{} +} + +func (p *PushServiceGetPusherOptionsResult) InitDefault() { + *p = PushServiceGetPusherOptionsResult{} +} + +var PushServiceGetPusherOptionsResult_Success_DEFAULT *GetPusherOptionsResponse + +func (p *PushServiceGetPusherOptionsResult) GetSuccess() (v *GetPusherOptionsResponse) { + if !p.IsSetSuccess() { + return PushServiceGetPusherOptionsResult_Success_DEFAULT + } + return p.Success +} +func (p *PushServiceGetPusherOptionsResult) SetSuccess(x interface{}) { + p.Success = x.(*GetPusherOptionsResponse) +} + +var fieldIDToName_PushServiceGetPusherOptionsResult = map[int16]string{ + 0: "success", +} + +func (p *PushServiceGetPusherOptionsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *PushServiceGetPusherOptionsResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PushServiceGetPusherOptionsResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsResult) ReadField0(iprot thrift.TProtocol) error { + _field := NewGetPusherOptionsResponse() + if err := _field.Read(iprot); err != nil { + return err + } + p.Success = _field + return nil +} + +func (p *PushServiceGetPusherOptionsResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("GetPusherOptions_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *PushServiceGetPusherOptionsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PushServiceGetPusherOptionsResult(%+v)", *p) + +} + +func (p *PushServiceGetPusherOptionsResult) DeepEqual(ano *PushServiceGetPusherOptionsResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *PushServiceGetPusherOptionsResult) Field0DeepEqual(src *GetPusherOptionsResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} diff --git a/kitex_gen/push/pushservice/client.go b/kitex_gen/push/pushservice/client.go index 6485e41..0e6ceee 100644 --- a/kitex_gen/push/pushservice/client.go +++ b/kitex_gen/push/pushservice/client.go @@ -12,9 +12,10 @@ import ( // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. type Client interface { - Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.PushResp, err error) - Add(ctx context.Context, req *config.PushConfig, callOptions ...callopt.Option) (err error) + Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.Resp, err error) + Add(ctx context.Context, req *config.PusherConfig, callOptions ...callopt.Option) (r *push.Resp, err error) List(ctx context.Context, req *push.ListPusherRequest, callOptions ...callopt.Option) (r *push.ListPusherResponse, err error) + GetPusherOptions(ctx context.Context, callOptions ...callopt.Option) (r *push.GetPusherOptionsResponse, err error) } // NewClient creates a client for the service defined in IDL. @@ -46,12 +47,12 @@ type kPushServiceClient struct { *kClient } -func (p *kPushServiceClient) Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.PushResp, err error) { +func (p *kPushServiceClient) Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.Resp, err error) { ctx = client.NewCtxWithCallOptions(ctx, callOptions) return p.kClient.Push(ctx, req) } -func (p *kPushServiceClient) Add(ctx context.Context, req *config.PushConfig, callOptions ...callopt.Option) (err error) { +func (p *kPushServiceClient) Add(ctx context.Context, req *config.PusherConfig, callOptions ...callopt.Option) (r *push.Resp, err error) { ctx = client.NewCtxWithCallOptions(ctx, callOptions) return p.kClient.Add(ctx, req) } @@ -60,3 +61,8 @@ func (p *kPushServiceClient) List(ctx context.Context, req *push.ListPusherReque ctx = client.NewCtxWithCallOptions(ctx, callOptions) return p.kClient.List(ctx, req) } + +func (p *kPushServiceClient) GetPusherOptions(ctx context.Context, callOptions ...callopt.Option) (r *push.GetPusherOptionsResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.GetPusherOptions(ctx) +} diff --git a/kitex_gen/push/pushservice/pushservice.go b/kitex_gen/push/pushservice/pushservice.go index e14ee6d..ff29ddd 100644 --- a/kitex_gen/push/pushservice/pushservice.go +++ b/kitex_gen/push/pushservice/pushservice.go @@ -35,6 +35,13 @@ var serviceMethods = map[string]kitex.MethodInfo{ false, kitex.WithStreamingMode(kitex.StreamingNone), ), + "GetPusherOptions": kitex.NewMethodInfo( + getPusherOptionsHandler, + newPushServiceGetPusherOptionsArgs, + newPushServiceGetPusherOptionsResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), } var ( @@ -121,12 +128,12 @@ func newPushServicePushResult() interface{} { func addHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { realArg := arg.(*push.PushServiceAddArgs) - - err := handler.(push.PushService).Add(ctx, realArg.Req) + realResult := result.(*push.PushServiceAddResult) + success, err := handler.(push.PushService).Add(ctx, realArg.Req) if err != nil { return err } - + realResult.Success = success return nil } func newPushServiceAddArgs() interface{} { @@ -155,6 +162,24 @@ func newPushServiceListResult() interface{} { return push.NewPushServiceListResult() } +func getPusherOptionsHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + _ = arg.(*push.PushServiceGetPusherOptionsArgs) + realResult := result.(*push.PushServiceGetPusherOptionsResult) + success, err := handler.(push.PushService).GetPusherOptions(ctx) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newPushServiceGetPusherOptionsArgs() interface{} { + return push.NewPushServiceGetPusherOptionsArgs() +} + +func newPushServiceGetPusherOptionsResult() interface{} { + return push.NewPushServiceGetPusherOptionsResult() +} + type kClient struct { c client.Client } @@ -165,7 +190,7 @@ func newServiceClient(c client.Client) *kClient { } } -func (p *kClient) Push(ctx context.Context, req *push.PushReq) (r *push.PushResp, err error) { +func (p *kClient) Push(ctx context.Context, req *push.PushReq) (r *push.Resp, err error) { var _args push.PushServicePushArgs _args.Req = req var _result push.PushServicePushResult @@ -175,14 +200,14 @@ func (p *kClient) Push(ctx context.Context, req *push.PushReq) (r *push.PushResp return _result.GetSuccess(), nil } -func (p *kClient) Add(ctx context.Context, req *config.PushConfig) (err error) { +func (p *kClient) Add(ctx context.Context, req *config.PusherConfig) (r *push.Resp, err error) { var _args push.PushServiceAddArgs _args.Req = req var _result push.PushServiceAddResult if err = p.c.Call(ctx, "Add", &_args, &_result); err != nil { return } - return nil + return _result.GetSuccess(), nil } func (p *kClient) List(ctx context.Context, req *push.ListPusherRequest) (r *push.ListPusherResponse, err error) { @@ -194,3 +219,12 @@ func (p *kClient) List(ctx context.Context, req *push.ListPusherRequest) (r *pus } return _result.GetSuccess(), nil } + +func (p *kClient) GetPusherOptions(ctx context.Context) (r *push.GetPusherOptionsResponse, err error) { + var _args push.PushServiceGetPusherOptionsArgs + var _result push.PushServiceGetPusherOptionsResult + if err = p.c.Call(ctx, "GetPusherOptions", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} diff --git a/main.go b/main.go index 6bbae46..3f0b88f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal" + "gitea.timerzz.com/kedaya_haitao/pusher/pushers" "net" "time" @@ -16,6 +18,8 @@ import ( ) func main() { + dal.Init() + pushers.Init() opts := kitexInit() svr := pushservice.NewServer(new(PushServiceImpl), opts...) @@ -30,6 +34,30 @@ func kitexInit() (opts []server.Option) { opts = append(opts, server. WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + + opts = append(opts, server. + WithTransHandlerFactory(&mixTransHandlerFactory{nil})) + // address addr, err := net.ResolveTCPAddr("tcp", conf.GetConf().Kitex.Address) if err != nil { diff --git a/model/pusher.go b/model/pusher.go new file mode 100644 index 0000000..6ecffcf --- /dev/null +++ b/model/pusher.go @@ -0,0 +1,33 @@ +package model + +import ( + "gorm.io/gorm" + "time" +) + +type PusherType int + +const ( + PusherType_AnPusher = iota + 1 +) + +type Pusher struct { + ID uint `gorm:"primaryKey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index"` + + Type PusherType `json:"type"` + Name string `json:"name"` + Remark string `json:"remark"` + RawOption string `json:"option" gorm:"type:json"` +} + +func (p *Pusher) TableName() string { + return "pusher" +} + +type AnPushOption struct { + Token string `json:"token"` + Channel string `json:"channel"` +} diff --git a/model/pusher_test.go b/model/pusher_test.go new file mode 100644 index 0000000..7bf5ff8 --- /dev/null +++ b/model/pusher_test.go @@ -0,0 +1,7 @@ +package model + +import "testing" + +func TestModel(t *testing.T) { + var a AnPushOption +} diff --git a/pushers/anPush.go b/pushers/anPush.go new file mode 100644 index 0000000..8916921 --- /dev/null +++ b/pushers/anPush.go @@ -0,0 +1,35 @@ +package pushers + +import ( + "context" + "fmt" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + "github.com/go-resty/resty/v2" + "strings" +) + +type AnPush struct { + opt *config.AnPush + client *resty.Client +} + +func NewAnPush(opt *config.AnPush) *AnPush { + return &AnPush{ + opt: opt, + client: resty.New().SetHeader("Content-Type", "application/x-www-form-urlencoded"), + } +} + +type msgResponse struct { + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` + Msgid uint64 `json:"msgid"` +} + +func (a *AnPush) Push(ctx context.Context, title, content string) error { + r := a.client.R().SetBody(strings.NewReader(fmt.Sprintf("title=%s&content=%s&channel=%s", title, content, a.opt.Channel))).SetContext(ctx) + var result msgResponse + r.SetResult(&result) + _, err := r.Post(fmt.Sprintf("https://api.anpush.com/push/%s", a.opt.Token)) + return err +} diff --git a/pushers/controller.go b/pushers/controller.go new file mode 100644 index 0000000..09c2ea1 --- /dev/null +++ b/pushers/controller.go @@ -0,0 +1,67 @@ +package pushers + +import ( + "context" + "gitea.timerzz.com/kedaya_haitao/pusher/biz/dal/postgres" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + "github.com/bytedance/sonic" + "golang.org/x/sync/errgroup" + "sync" +) + +func Init() { + c = &Controller{ + pushers: make(map[int64]Pusher), + } +} + +func Push(ctx context.Context, ids []int64, title, content string) error { + return c.Push(ctx, ids, title, content) +} + +type Pusher interface { + Push(ctx context.Context, title, content string) error +} + +type Controller struct { + pushers map[int64]Pusher + l sync.Mutex +} + +var c *Controller + +func (c *Controller) Push(ctx context.Context, ids []int64, title, content string) error { + wg, sub := errgroup.WithContext(ctx) + for _, id := range ids { + var i = id + wg.Go(func() error { + if pusher, ok := c.pushers[i]; ok { + return pusher.Push(sub, title, content) + } else { + var cfg config.PusherConfig + if err := postgres.DB.Where("id = ?", i).Find(&cfg).Error; err != nil { + return err + } + c.l.Lock() + c.pushers[cfg.Id] = NewPusher(cfg) + c.l.Unlock() + return c.pushers[cfg.Id].Push(sub, title, content) + } + }) + } + return wg.Wait() +} + +func NewPusher(cfg config.PusherConfig) Pusher { + switch cfg.Type { + case config.PusherConfigType_AnPush: + var opt config.AnPush + _ = sonic.UnmarshalString(cfg.Option, &opt) + return NewAnPush(&opt) + case config.PusherConfigType_Email: + var opt config.EmailPush + _ = sonic.UnmarshalString(cfg.Option, &opt) + return NewEmailPusher(&opt) + } + return nil +} diff --git a/pushers/email.go b/pushers/email.go new file mode 100644 index 0000000..9f2b349 --- /dev/null +++ b/pushers/email.go @@ -0,0 +1,35 @@ +package pushers + +import ( + "context" + "fmt" + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + "github.com/wneessen/go-mail" +) + +type Email struct { + opt *config.EmailPush +} + +func NewEmailPusher(opt *config.EmailPush) *Email { + return &Email{opt: opt} +} + +func (e *Email) Push(ctx context.Context, title, content string) error { + em := mail.NewMsg() + if err := em.From(e.opt.From); err != nil { + return fmt.Errorf("设置from失败:%v", err) + } + if err := em.To(e.opt.To); err != nil { + return fmt.Errorf("设置to失败:%v", err) + } + em.Subject(title) + em.SetBodyString(mail.TypeTextPlain, content) + + c, err := mail.NewClient(e.opt.Host, mail.WithPort(int(e.opt.Port)), mail.WithSMTPAuth(mail.SMTPAuthPlain), + mail.WithUsername(e.opt.Username), mail.WithPassword(e.opt.Password)) + if err != nil { + return fmt.Errorf("创建email客户端失败:%v", err) + } + return c.DialAndSendWithContext(ctx, em) +} diff --git a/rpc/pusher/pusher_client.go b/rpc/pusher/pusher_client.go new file mode 100644 index 0000000..06bc65e --- /dev/null +++ b/rpc/pusher/pusher_client.go @@ -0,0 +1,62 @@ +package pusher + +import ( + "context" + config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" + + "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push/pushservice" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/client/callopt" +) + +type RPCClient interface { + KitexClient() pushservice.Client + Service() string + Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.Resp, err error) + Add(ctx context.Context, req *config.PusherConfig, callOptions ...callopt.Option) (r *push.Resp, err error) + List(ctx context.Context, req *push.ListPusherRequest, callOptions ...callopt.Option) (r *push.ListPusherResponse, err error) + GetPusherOptions(ctx context.Context, callOptions ...callopt.Option) (r *push.GetPusherOptionsResponse, err error) +} + +func NewRPCClient(dstService string, opts ...client.Option) (RPCClient, error) { + kitexClient, err := pushservice.NewClient(dstService, opts...) + if err != nil { + return nil, err + } + cli := &clientImpl{ + service: dstService, + kitexClient: kitexClient, + } + + return cli, nil +} + +type clientImpl struct { + service string + kitexClient pushservice.Client +} + +func (c *clientImpl) Service() string { + return c.service +} + +func (c *clientImpl) KitexClient() pushservice.Client { + return c.kitexClient +} + +func (c *clientImpl) Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (r *push.Resp, err error) { + return c.kitexClient.Push(ctx, req, callOptions...) +} + +func (c *clientImpl) Add(ctx context.Context, req *config.PusherConfig, callOptions ...callopt.Option) (r *push.Resp, err error) { + return c.kitexClient.Add(ctx, req, callOptions...) +} + +func (c *clientImpl) List(ctx context.Context, req *push.ListPusherRequest, callOptions ...callopt.Option) (r *push.ListPusherResponse, err error) { + return c.kitexClient.List(ctx, req, callOptions...) +} + +func (c *clientImpl) GetPusherOptions(ctx context.Context, callOptions ...callopt.Option) (r *push.GetPusherOptionsResponse, err error) { + return c.kitexClient.GetPusherOptions(ctx, callOptions...) +} diff --git a/rpc/pusher/pusher_default.go b/rpc/pusher/pusher_default.go new file mode 100644 index 0000000..15a2b11 --- /dev/null +++ b/rpc/pusher/pusher_default.go @@ -0,0 +1,45 @@ +package pusher + +import ( + "context" + config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config" + push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push" + "github.com/cloudwego/kitex/client/callopt" + "github.com/cloudwego/kitex/pkg/klog" +) + +func Push(ctx context.Context, req *push.PushReq, callOptions ...callopt.Option) (resp *push.Resp, err error) { + resp, err = defaultClient.Push(ctx, req, callOptions...) + if err != nil { + klog.CtxErrorf(ctx, "Push call failed,err =%+v", err) + return nil, err + } + return resp, nil +} + +func Add(ctx context.Context, req *config.PusherConfig, callOptions ...callopt.Option) (resp *push.Resp, err error) { + resp, err = defaultClient.Add(ctx, req, callOptions...) + if err != nil { + klog.CtxErrorf(ctx, "Add call failed,err =%+v", err) + return nil, err + } + return resp, nil +} + +func List(ctx context.Context, req *push.ListPusherRequest, callOptions ...callopt.Option) (resp *push.ListPusherResponse, err error) { + resp, err = defaultClient.List(ctx, req, callOptions...) + if err != nil { + klog.CtxErrorf(ctx, "List call failed,err =%+v", err) + return nil, err + } + return resp, nil +} + +func GetPusherOptions(ctx context.Context, callOptions ...callopt.Option) (resp *push.GetPusherOptionsResponse, err error) { + resp, err = defaultClient.GetPusherOptions(ctx, callOptions...) + if err != nil { + klog.CtxErrorf(ctx, "GetPusherOptions call failed,err =%+v", err) + return nil, err + } + return resp, nil +} diff --git a/rpc/pusher/pusher_init.go b/rpc/pusher/pusher_init.go new file mode 100644 index 0000000..9ab6e60 --- /dev/null +++ b/rpc/pusher/pusher_init.go @@ -0,0 +1,44 @@ +package pusher + +import ( + "sync" + + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/pkg/transmeta" + "github.com/cloudwego/kitex/transport" +) + +var ( + // todo edit custom config + defaultClient RPCClient + defaultDstService = "pusher" + defaultClientOpts = []client.Option{ + client.WithHostPorts("127.0.0.1:8888"), + client.WithMetaHandler(transmeta.ClientTTHeaderHandler), + client.WithTransportProtocol(transport.TTHeader), + } + once sync.Once +) + +func init() { + DefaultClient() +} + +func DefaultClient() RPCClient { + once.Do(func() { + defaultClient = newClient(defaultDstService, defaultClientOpts...) + }) + return defaultClient +} + +func newClient(dstService string, opts ...client.Option) RPCClient { + c, err := NewRPCClient(dstService, opts...) + if err != nil { + panic("failed to init client: " + err.Error()) + } + return c +} + +func InitClient(dstService string, opts ...client.Option) { + defaultClient = newClient(dstService, opts...) +} diff --git a/script/bootstrap.sh b/script/bootstrap.sh deleted file mode 100644 index 2d04afe..0000000 --- a/script/bootstrap.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash -CURDIR=$(cd $(dirname $0); pwd) -echo "$CURDIR/bin/pusher" -exec "$CURDIR/bin/pusher" \ No newline at end of file