You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.6 KiB
119 lines
3.6 KiB
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
|
// versions:
|
|
// - protoc-gen-go-http v2.7.0
|
|
// - protoc v3.21.12
|
|
// source: sms.proto
|
|
|
|
package api
|
|
|
|
import (
|
|
context "context"
|
|
http "github.com/go-kratos/kratos/v2/transport/http"
|
|
binding "github.com/go-kratos/kratos/v2/transport/http/binding"
|
|
)
|
|
|
|
// This is a compile-time assertion to ensure that this generated file
|
|
// is compatible with the kratos package it is being compiled against.
|
|
var _ = new(context.Context)
|
|
var _ = binding.EncodeURL
|
|
|
|
const _ = http.SupportPackageIsVersion1
|
|
|
|
const OperationSmsSendMessage = "/api.Sms/SendMessage"
|
|
const OperationSmsVerifyCode = "/api.Sms/VerifyCode"
|
|
|
|
type SmsHTTPServer interface {
|
|
// SendMessage 发送一条短信
|
|
SendMessage(context.Context, *SendSmsRequest) (*SendSmsReply, error)
|
|
// VerifyCode 校验短信code
|
|
VerifyCode(context.Context, *SmsCodeVerifyRequest) (*SendSmsReply, error)
|
|
}
|
|
|
|
func RegisterSmsHTTPServer(s *http.Server, srv SmsHTTPServer) {
|
|
r := s.Route("/")
|
|
r.POST("sms/send", _Sms_SendMessage0_HTTP_Handler(srv))
|
|
r.POST("sms/code-verify", _Sms_VerifyCode0_HTTP_Handler(srv))
|
|
}
|
|
|
|
func _Sms_SendMessage0_HTTP_Handler(srv SmsHTTPServer) func(ctx http.Context) error {
|
|
return func(ctx http.Context) error {
|
|
var in SendSmsRequest
|
|
if err := ctx.Bind(&in); err != nil {
|
|
return err
|
|
}
|
|
if err := ctx.BindQuery(&in); err != nil {
|
|
return err
|
|
}
|
|
http.SetOperation(ctx, OperationSmsSendMessage)
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.SendMessage(ctx, req.(*SendSmsRequest))
|
|
})
|
|
out, err := h(ctx, &in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
reply := out.(*SendSmsReply)
|
|
return ctx.Result(200, reply)
|
|
}
|
|
}
|
|
|
|
func _Sms_VerifyCode0_HTTP_Handler(srv SmsHTTPServer) func(ctx http.Context) error {
|
|
return func(ctx http.Context) error {
|
|
var in SmsCodeVerifyRequest
|
|
if err := ctx.Bind(&in); err != nil {
|
|
return err
|
|
}
|
|
if err := ctx.BindQuery(&in); err != nil {
|
|
return err
|
|
}
|
|
http.SetOperation(ctx, OperationSmsVerifyCode)
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.VerifyCode(ctx, req.(*SmsCodeVerifyRequest))
|
|
})
|
|
out, err := h(ctx, &in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
reply := out.(*SendSmsReply)
|
|
return ctx.Result(200, reply)
|
|
}
|
|
}
|
|
|
|
type SmsHTTPClient interface {
|
|
SendMessage(ctx context.Context, req *SendSmsRequest, opts ...http.CallOption) (rsp *SendSmsReply, err error)
|
|
VerifyCode(ctx context.Context, req *SmsCodeVerifyRequest, opts ...http.CallOption) (rsp *SendSmsReply, err error)
|
|
}
|
|
|
|
type SmsHTTPClientImpl struct {
|
|
cc *http.Client
|
|
}
|
|
|
|
func NewSmsHTTPClient(client *http.Client) SmsHTTPClient {
|
|
return &SmsHTTPClientImpl{client}
|
|
}
|
|
|
|
func (c *SmsHTTPClientImpl) SendMessage(ctx context.Context, in *SendSmsRequest, opts ...http.CallOption) (*SendSmsReply, error) {
|
|
var out SendSmsReply
|
|
pattern := "sms/send"
|
|
path := binding.EncodeURL(pattern, in, false)
|
|
opts = append(opts, http.Operation(OperationSmsSendMessage))
|
|
opts = append(opts, http.PathTemplate(pattern))
|
|
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &out, err
|
|
}
|
|
|
|
func (c *SmsHTTPClientImpl) VerifyCode(ctx context.Context, in *SmsCodeVerifyRequest, opts ...http.CallOption) (*SendSmsReply, error) {
|
|
var out SendSmsReply
|
|
pattern := "sms/code-verify"
|
|
path := binding.EncodeURL(pattern, in, false)
|
|
opts = append(opts, http.Operation(OperationSmsVerifyCode))
|
|
opts = append(opts, http.PathTemplate(pattern))
|
|
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &out, err
|
|
}
|
|
|