greeter_http.pb.go 2.14 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2
// Code generated by protoc-gen-go-http. DO NOT EDIT.
// versions:
kzkzzzz's avatar
kzkzzzz committed
3
// protoc-gen-go-http v2.3.1
kzkzzzz's avatar
kzkzzzz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

package v1

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

kzkzzzz's avatar
kzkzzzz committed
20 21
const OperationGreeterSayHello = "/helloworld.v1.Greeter/SayHello"

kzkzzzz's avatar
kzkzzzz committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
type GreeterHTTPServer interface {
	SayHello(context.Context, *HelloRequest) (*HelloReply, error)
}

func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) {
	r := s.Route("/")
	r.GET("/helloworld/{name}", _Greeter_SayHello0_HTTP_Handler(srv))
}

func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in HelloRequest
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		if err := ctx.BindVars(&in); err != nil {
			return err
		}
kzkzzzz's avatar
kzkzzzz committed
40
		http.SetOperation(ctx, OperationGreeterSayHello)
kzkzzzz's avatar
kzkzzzz committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.SayHello(ctx, req.(*HelloRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*HelloReply)
		return ctx.Result(200, reply)
	}
}

type GreeterHTTPClient interface {
	SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (rsp *HelloReply, err error)
}

type GreeterHTTPClientImpl struct {
	cc *http.Client
}

func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient {
	return &GreeterHTTPClientImpl{client}
}

func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) {
	var out HelloReply
	pattern := "/helloworld/{name}"
	path := binding.EncodeURL(pattern, in, true)
kzkzzzz's avatar
kzkzzzz committed
69
	opts = append(opts, http.Operation(OperationGreeterSayHello))
kzkzzzz's avatar
kzkzzzz committed
70 71 72 73 74 75 76
	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
}