demo_http.pb.go 7.8 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
// Code generated by protoc-gen-go-http. DO NOT EDIT.
// versions:
// - protoc-gen-go-http v2.3.1
// - protoc             v3.19.4
// source: demo.proto

package demo

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 OperationDemoCreate = "/demo.Demo/Create"
const OperationDemoDelete = "/demo.Demo/Delete"
const OperationDemoGet = "/demo.Demo/Get"
const OperationDemoHello = "/demo.Demo/Hello"
const OperationDemoList = "/demo.Demo/List"
const OperationDemoUpdate = "/demo.Demo/Update"

type DemoHTTPServer interface {
	Create(context.Context, *CreateReq) (*OKRep, error)
	Delete(context.Context, *IdReq) (*OKRep, error)
	Get(context.Context, *IdReq) (*DemoModel, error)
	Hello(context.Context, *HelloReq) (*HelloRep, error)
	List(context.Context, *ListReq) (*ListRep, error)
	Update(context.Context, *UpdateReq) (*OKRep, error)
}

func RegisterDemoHTTPServer(s *http.Server, srv DemoHTTPServer) {
	r := s.Route("/")
	r.GET("/demo/hello/{name}", _Demo_Hello0_HTTP_Handler(srv))
	r.POST("/demo/create", _Demo_Create0_HTTP_Handler(srv))
	r.POST("/demo/update", _Demo_Update0_HTTP_Handler(srv))
	r.GET("/demo/get", _Demo_Get0_HTTP_Handler(srv))
	r.GET("/demo/list", _Demo_List0_HTTP_Handler(srv))
	r.GET("/demo/delete", _Demo_Delete0_HTTP_Handler(srv))
}

func _Demo_Hello0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in HelloReq
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		if err := ctx.BindVars(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoHello)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.Hello(ctx, req.(*HelloReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*HelloRep)
		return ctx.Result(200, reply)
	}
}

func _Demo_Create0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in CreateReq
		if err := ctx.Bind(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoCreate)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.Create(ctx, req.(*CreateReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*OKRep)
		return ctx.Result(200, reply)
	}
}

func _Demo_Update0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in UpdateReq
		if err := ctx.Bind(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoUpdate)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.Update(ctx, req.(*UpdateReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*OKRep)
		return ctx.Result(200, reply)
	}
}

func _Demo_Get0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in IdReq
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoGet)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.Get(ctx, req.(*IdReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*DemoModel)
		return ctx.Result(200, reply)
	}
}

func _Demo_List0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in ListReq
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoList)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.List(ctx, req.(*ListReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*ListRep)
		return ctx.Result(200, reply)
	}
}

func _Demo_Delete0_HTTP_Handler(srv DemoHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in IdReq
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationDemoDelete)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.Delete(ctx, req.(*IdReq))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*OKRep)
		return ctx.Result(200, reply)
	}
}

type DemoHTTPClient interface {
	Create(ctx context.Context, req *CreateReq, opts ...http.CallOption) (rsp *OKRep, err error)
	Delete(ctx context.Context, req *IdReq, opts ...http.CallOption) (rsp *OKRep, err error)
	Get(ctx context.Context, req *IdReq, opts ...http.CallOption) (rsp *DemoModel, err error)
	Hello(ctx context.Context, req *HelloReq, opts ...http.CallOption) (rsp *HelloRep, err error)
	List(ctx context.Context, req *ListReq, opts ...http.CallOption) (rsp *ListRep, err error)
	Update(ctx context.Context, req *UpdateReq, opts ...http.CallOption) (rsp *OKRep, err error)
}

type DemoHTTPClientImpl struct {
	cc *http.Client
}

func NewDemoHTTPClient(client *http.Client) DemoHTTPClient {
	return &DemoHTTPClientImpl{client}
}

func (c *DemoHTTPClientImpl) Create(ctx context.Context, in *CreateReq, opts ...http.CallOption) (*OKRep, error) {
	var out OKRep
	pattern := "/demo/create"
	path := binding.EncodeURL(pattern, in, false)
	opts = append(opts, http.Operation(OperationDemoCreate))
	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 *DemoHTTPClientImpl) Delete(ctx context.Context, in *IdReq, opts ...http.CallOption) (*OKRep, error) {
	var out OKRep
	pattern := "/demo/delete"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationDemoDelete))
	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 *DemoHTTPClientImpl) Get(ctx context.Context, in *IdReq, opts ...http.CallOption) (*DemoModel, error) {
	var out DemoModel
	pattern := "/demo/get"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationDemoGet))
	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 *DemoHTTPClientImpl) Hello(ctx context.Context, in *HelloReq, opts ...http.CallOption) (*HelloRep, error) {
	var out HelloRep
	pattern := "/demo/hello/{name}"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationDemoHello))
	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 *DemoHTTPClientImpl) List(ctx context.Context, in *ListReq, opts ...http.CallOption) (*ListRep, error) {
	var out ListRep
	pattern := "/demo/list"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationDemoList))
	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 *DemoHTTPClientImpl) Update(ctx context.Context, in *UpdateReq, opts ...http.CallOption) (*OKRep, error) {
	var out OKRep
	pattern := "/demo/update"
	path := binding.EncodeURL(pattern, in, false)
	opts = append(opts, http.Operation(OperationDemoUpdate))
	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
}