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.
111 lines
3.3 KiB
111 lines
3.3 KiB
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
|
// versions:
|
|
// protoc-gen-go-http v2.3.1
|
|
|
|
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 OperationGreeterPing = "/api.Greeter/Ping"
|
|
const OperationGreeterUpload = "/api.Greeter/Upload"
|
|
|
|
type GreeterHTTPServer interface {
|
|
Ping(context.Context, *PingRequest) (*PingReply, error)
|
|
Upload(context.Context, *UploadRequest) (*UploadReply, error)
|
|
}
|
|
|
|
func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) {
|
|
r := s.Route("/")
|
|
r.GET("/ping", _Greeter_Ping0_HTTP_Handler(srv))
|
|
r.POST("/upload", _Greeter_Upload0_HTTP_Handler(srv))
|
|
}
|
|
|
|
func _Greeter_Ping0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error {
|
|
return func(ctx http.Context) error {
|
|
var in PingRequest
|
|
if err := ctx.BindQuery(&in); err != nil {
|
|
return err
|
|
}
|
|
http.SetOperation(ctx, OperationGreeterPing)
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.Ping(ctx, req.(*PingRequest))
|
|
})
|
|
out, err := h(ctx, &in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
reply := out.(*PingReply)
|
|
return ctx.Result(200, reply)
|
|
}
|
|
}
|
|
|
|
func _Greeter_Upload0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error {
|
|
return func(ctx http.Context) error {
|
|
var in UploadRequest
|
|
if err := ctx.BindForm(&in); err != nil {
|
|
return err
|
|
}
|
|
// ctx.Request().FormFile("file")
|
|
in.Type=ctx.Request().FormValue("type")
|
|
http.SetOperation(ctx, OperationGreeterUpload)
|
|
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.Upload(ctx, req.(*UploadRequest))
|
|
})
|
|
out, err := h(ctx, &in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
reply := out.(*UploadReply)
|
|
return ctx.Result(200, reply)
|
|
}
|
|
}
|
|
|
|
type GreeterHTTPClient interface {
|
|
Ping(ctx context.Context, req *PingRequest, opts ...http.CallOption) (rsp *PingReply, err error)
|
|
Upload(ctx context.Context, req *UploadRequest, opts ...http.CallOption) (rsp *UploadReply, err error)
|
|
}
|
|
|
|
type GreeterHTTPClientImpl struct {
|
|
cc *http.Client
|
|
}
|
|
|
|
func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient {
|
|
return &GreeterHTTPClientImpl{client}
|
|
}
|
|
|
|
func (c *GreeterHTTPClientImpl) Ping(ctx context.Context, in *PingRequest, opts ...http.CallOption) (*PingReply, error) {
|
|
var out PingReply
|
|
pattern := "/ping"
|
|
path := binding.EncodeURL(pattern, in, true)
|
|
opts = append(opts, http.Operation(OperationGreeterPing))
|
|
opts = append(opts, http.PathTemplate(pattern))
|
|
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &out, err
|
|
}
|
|
|
|
func (c *GreeterHTTPClientImpl) Upload(ctx context.Context, in *UploadRequest, opts ...http.CallOption) (*UploadReply, error) {
|
|
var out UploadReply
|
|
pattern := "/upload"
|
|
path := binding.EncodeURL(pattern, in, false)
|
|
opts = append(opts, http.Operation(OperationGreeterUpload))
|
|
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
|
|
}
|
|
|