pusher/kitex_gen/push/pushservice/pushservice.go

231 lines
6.2 KiB
Go
Raw Normal View History

2024-11-29 21:53:59 +08:00
// Code generated by Kitex v0.9.1. DO NOT EDIT.
2024-05-17 18:02:10 +08:00
package pushservice
import (
"context"
"errors"
config "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
push "gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push"
client "github.com/cloudwego/kitex/client"
kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
)
var errInvalidMessageType = errors.New("invalid message type for service method handler")
var serviceMethods = map[string]kitex.MethodInfo{
"Push": kitex.NewMethodInfo(
pushHandler,
newPushServicePushArgs,
newPushServicePushResult,
false,
kitex.WithStreamingMode(kitex.StreamingNone),
),
"Add": kitex.NewMethodInfo(
addHandler,
newPushServiceAddArgs,
newPushServiceAddResult,
false,
kitex.WithStreamingMode(kitex.StreamingNone),
),
"List": kitex.NewMethodInfo(
listHandler,
newPushServiceListArgs,
newPushServiceListResult,
false,
kitex.WithStreamingMode(kitex.StreamingNone),
),
2024-05-20 17:57:25 +08:00
"GetPusherOptions": kitex.NewMethodInfo(
getPusherOptionsHandler,
newPushServiceGetPusherOptionsArgs,
newPushServiceGetPusherOptionsResult,
false,
kitex.WithStreamingMode(kitex.StreamingNone),
),
2024-05-17 18:02:10 +08:00
}
var (
pushServiceServiceInfo = NewServiceInfo()
pushServiceServiceInfoForClient = NewServiceInfoForClient()
pushServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient()
)
// for server
func serviceInfo() *kitex.ServiceInfo {
return pushServiceServiceInfo
}
// for client
func serviceInfoForStreamClient() *kitex.ServiceInfo {
return pushServiceServiceInfoForStreamClient
}
// for stream client
func serviceInfoForClient() *kitex.ServiceInfo {
return pushServiceServiceInfoForClient
}
// NewServiceInfo creates a new ServiceInfo containing all methods
func NewServiceInfo() *kitex.ServiceInfo {
return newServiceInfo(false, true, true)
}
// NewServiceInfo creates a new ServiceInfo containing non-streaming methods
func NewServiceInfoForClient() *kitex.ServiceInfo {
return newServiceInfo(false, false, true)
}
func NewServiceInfoForStreamClient() *kitex.ServiceInfo {
return newServiceInfo(true, true, false)
}
func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo {
serviceName := "PushService"
handlerType := (*push.PushService)(nil)
methods := map[string]kitex.MethodInfo{}
for name, m := range serviceMethods {
if m.IsStreaming() && !keepStreamingMethods {
continue
}
if !m.IsStreaming() && !keepNonStreamingMethods {
continue
}
methods[name] = m
}
extra := map[string]interface{}{
"PackageName": "push",
}
if hasStreaming {
extra["streaming"] = hasStreaming
}
svcInfo := &kitex.ServiceInfo{
ServiceName: serviceName,
HandlerType: handlerType,
Methods: methods,
PayloadCodec: kitex.Thrift,
2024-11-29 21:53:59 +08:00
KiteXGenVersion: "v0.9.1",
2024-05-17 18:02:10 +08:00
Extra: extra,
}
return svcInfo
}
func pushHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
realArg := arg.(*push.PushServicePushArgs)
realResult := result.(*push.PushServicePushResult)
success, err := handler.(push.PushService).Push(ctx, realArg.Req)
if err != nil {
return err
}
realResult.Success = success
return nil
}
func newPushServicePushArgs() interface{} {
return push.NewPushServicePushArgs()
}
func newPushServicePushResult() interface{} {
return push.NewPushServicePushResult()
}
func addHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
realArg := arg.(*push.PushServiceAddArgs)
2024-05-20 17:57:25 +08:00
realResult := result.(*push.PushServiceAddResult)
success, err := handler.(push.PushService).Add(ctx, realArg.Req)
2024-05-17 18:02:10 +08:00
if err != nil {
return err
}
2024-05-20 17:57:25 +08:00
realResult.Success = success
2024-05-17 18:02:10 +08:00
return nil
}
func newPushServiceAddArgs() interface{} {
return push.NewPushServiceAddArgs()
}
func newPushServiceAddResult() interface{} {
return push.NewPushServiceAddResult()
}
func listHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
realArg := arg.(*push.PushServiceListArgs)
realResult := result.(*push.PushServiceListResult)
success, err := handler.(push.PushService).List(ctx, realArg.Req)
if err != nil {
return err
}
realResult.Success = success
return nil
}
func newPushServiceListArgs() interface{} {
return push.NewPushServiceListArgs()
}
func newPushServiceListResult() interface{} {
return push.NewPushServiceListResult()
}
2024-05-20 17:57:25 +08:00
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()
}
2024-05-17 18:02:10 +08:00
type kClient struct {
c client.Client
}
func newServiceClient(c client.Client) *kClient {
return &kClient{
c: c,
}
}
2024-05-20 17:57:25 +08:00
func (p *kClient) Push(ctx context.Context, req *push.PushReq) (r *push.Resp, err error) {
2024-05-17 18:02:10 +08:00
var _args push.PushServicePushArgs
_args.Req = req
var _result push.PushServicePushResult
if err = p.c.Call(ctx, "Push", &_args, &_result); err != nil {
return
}
return _result.GetSuccess(), nil
}
2024-05-20 17:57:25 +08:00
func (p *kClient) Add(ctx context.Context, req *config.PusherConfig) (r *push.Resp, err error) {
2024-05-17 18:02:10 +08:00
var _args push.PushServiceAddArgs
_args.Req = req
var _result push.PushServiceAddResult
if err = p.c.Call(ctx, "Add", &_args, &_result); err != nil {
return
}
2024-05-20 17:57:25 +08:00
return _result.GetSuccess(), nil
2024-05-17 18:02:10 +08:00
}
func (p *kClient) List(ctx context.Context, req *push.ListPusherRequest) (r *push.ListPusherResponse, err error) {
var _args push.PushServiceListArgs
_args.Req = req
var _result push.PushServiceListResult
if err = p.c.Call(ctx, "List", &_args, &_result); err != nil {
return
}
return _result.GetSuccess(), nil
}
2024-05-20 17:57:25 +08:00
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
}