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.
127 lines
3.4 KiB
127 lines
3.4 KiB
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
|
|
|
package metadata
|
|
|
|
import (
|
|
context "context"
|
|
http1 "github.com/go-kratos/kratos/v2/transport/http"
|
|
binding "github.com/go-kratos/kratos/v2/transport/http/binding"
|
|
mux "github.com/gorilla/mux"
|
|
http "net/http"
|
|
)
|
|
|
|
// 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(http.Request)
|
|
var _ = new(context.Context)
|
|
var _ = binding.MapProto
|
|
var _ = mux.NewRouter
|
|
|
|
const _ = http1.SupportPackageIsVersion1
|
|
|
|
type MetadataHandler interface {
|
|
GetServiceDesc(context.Context, *GetServiceDescRequest) (*GetServiceDescReply, error)
|
|
|
|
ListServices(context.Context, *ListServicesRequest) (*ListServicesReply, error)
|
|
}
|
|
|
|
func NewMetadataHandler(srv MetadataHandler, opts ...http1.HandleOption) http.Handler {
|
|
h := http1.DefaultHandleOptions()
|
|
for _, o := range opts {
|
|
o(&h)
|
|
}
|
|
r := mux.NewRouter()
|
|
|
|
r.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
|
|
var in ListServicesRequest
|
|
if err := h.Decode(r, &in); err != nil {
|
|
h.Error(w, r, err)
|
|
return
|
|
}
|
|
|
|
next := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.ListServices(ctx, req.(*ListServicesRequest))
|
|
}
|
|
if h.Middleware != nil {
|
|
next = h.Middleware(next)
|
|
}
|
|
out, err := next(r.Context(), &in)
|
|
if err != nil {
|
|
h.Error(w, r, err)
|
|
return
|
|
}
|
|
reply := out.(*ListServicesReply)
|
|
if err := h.Encode(w, r, reply); err != nil {
|
|
h.Error(w, r, err)
|
|
}
|
|
}).Methods("GET")
|
|
|
|
r.HandleFunc("/services/{name}", func(w http.ResponseWriter, r *http.Request) {
|
|
var in GetServiceDescRequest
|
|
if err := h.Decode(r, &in); err != nil {
|
|
h.Error(w, r, err)
|
|
return
|
|
}
|
|
|
|
if err := binding.BindVars(mux.Vars(r), &in); err != nil {
|
|
h.Error(w, r, err)
|
|
return
|
|
}
|
|
|
|
next := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.GetServiceDesc(ctx, req.(*GetServiceDescRequest))
|
|
}
|
|
if h.Middleware != nil {
|
|
next = h.Middleware(next)
|
|
}
|
|
out, err := next(r.Context(), &in)
|
|
if err != nil {
|
|
h.Error(w, r, err)
|
|
return
|
|
}
|
|
reply := out.(*GetServiceDescReply)
|
|
if err := h.Encode(w, r, reply); err != nil {
|
|
h.Error(w, r, err)
|
|
}
|
|
}).Methods("GET")
|
|
|
|
return r
|
|
}
|
|
|
|
type MetadataHTTPClient interface {
|
|
GetServiceDesc(ctx context.Context, req *GetServiceDescRequest, opts ...http1.CallOption) (rsp *GetServiceDescReply, err error)
|
|
|
|
ListServices(ctx context.Context, req *ListServicesRequest, opts ...http1.CallOption) (rsp *ListServicesReply, err error)
|
|
}
|
|
|
|
type MetadataHTTPClientImpl struct {
|
|
cc *http1.Client
|
|
}
|
|
|
|
func NewMetadataHTTPClient(client *http1.Client) MetadataHTTPClient {
|
|
return &MetadataHTTPClientImpl{client}
|
|
}
|
|
|
|
func (c *MetadataHTTPClientImpl) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest, opts ...http1.CallOption) (out *GetServiceDescReply, err error) {
|
|
path := binding.EncodePath("GET", "/services/{name}", in)
|
|
out = &GetServiceDescReply{}
|
|
|
|
err = c.cc.Invoke(ctx, path, nil, &out, http1.Method("GET"), http1.PathPattern("/services/{name}"))
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (c *MetadataHTTPClientImpl) ListServices(ctx context.Context, in *ListServicesRequest, opts ...http1.CallOption) (out *ListServicesReply, err error) {
|
|
path := binding.EncodePath("GET", "/services", in)
|
|
out = &ListServicesReply{}
|
|
|
|
err = c.cc.Invoke(ctx, path, nil, &out, http1.Method("GET"), http1.PathPattern("/services"))
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|