greeter_http.pb.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Code generated by protoc-gen-go-http. DO NOT EDIT.
  2. // versions:
  3. // - protoc-gen-go-http v2.8.4
  4. // - protoc v3.20.0--rc1
  5. // source: helloworld/v1/greeter.proto
  6. package v1
  7. import (
  8. context "context"
  9. http "github.com/go-kratos/kratos/v2/transport/http"
  10. binding "github.com/go-kratos/kratos/v2/transport/http/binding"
  11. )
  12. // This is a compile-time assertion to ensure that this generated file
  13. // is compatible with the kratos package it is being compiled against.
  14. var _ = new(context.Context)
  15. var _ = binding.EncodeURL
  16. const _ = http.SupportPackageIsVersion1
  17. const OperationGreeterSayHello = "/helloworld.v1.Greeter/SayHello"
  18. type GreeterHTTPServer interface {
  19. // SayHello Sends a greeting
  20. SayHello(context.Context, *HelloRequest) (*HelloReply, error)
  21. }
  22. func RegisterGreeterHTTPServer(s *http.Server, srv GreeterHTTPServer) {
  23. r := s.Route("/")
  24. r.GET("/helloworld/{name}", _Greeter_SayHello0_HTTP_Handler(srv))
  25. }
  26. func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) func(ctx http.Context) error {
  27. return func(ctx http.Context) error {
  28. var in HelloRequest
  29. if err := ctx.BindQuery(&in); err != nil {
  30. return err
  31. }
  32. if err := ctx.BindVars(&in); err != nil {
  33. return err
  34. }
  35. http.SetOperation(ctx, OperationGreeterSayHello)
  36. h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
  37. return srv.SayHello(ctx, req.(*HelloRequest))
  38. })
  39. out, err := h(ctx, &in)
  40. if err != nil {
  41. return err
  42. }
  43. reply := out.(*HelloReply)
  44. return ctx.Result(200, reply)
  45. }
  46. }
  47. type GreeterHTTPClient interface {
  48. SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (rsp *HelloReply, err error)
  49. }
  50. type GreeterHTTPClientImpl struct {
  51. cc *http.Client
  52. }
  53. func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient {
  54. return &GreeterHTTPClientImpl{client}
  55. }
  56. func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) {
  57. var out HelloReply
  58. pattern := "/helloworld/{name}"
  59. path := binding.EncodeURL(pattern, in, true)
  60. opts = append(opts, http.Operation(OperationGreeterSayHello))
  61. opts = append(opts, http.PathTemplate(pattern))
  62. err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
  63. if err != nil {
  64. return nil, err
  65. }
  66. return &out, nil
  67. }