use never protoc-gen-micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -2,6 +2,7 @@ syntax = "proto3";
|
||||
|
||||
package github;
|
||||
option go_package = "github.com//unistack-org/micro-tests/client/http/proto;pb";
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "protoc-gen-openapiv2/options/annotations.proto";
|
||||
|
||||
@@ -13,28 +14,19 @@ service Github {
|
||||
key: "default";
|
||||
value: {
|
||||
description: "Error response";
|
||||
schema: {
|
||||
json_schema: {
|
||||
ref: ".github.Error";
|
||||
}
|
||||
}
|
||||
schema: { json_schema: { ref: ".github.Error"; } }
|
||||
}
|
||||
}
|
||||
};
|
||||
option (google.api.http) = {
|
||||
get: "/users/{username}";
|
||||
};
|
||||
option (google.api.http) = { get: "/users/{username}"; };
|
||||
};
|
||||
};
|
||||
|
||||
message LookupUserReq {
|
||||
string username = 1;
|
||||
};
|
||||
|
||||
message LookupUserRsp {
|
||||
string name = 1;
|
||||
};
|
||||
|
||||
message Error {
|
||||
string message = 1;
|
||||
};
|
||||
|
@@ -5,13 +5,8 @@ package pb
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
micro_client_http "github.com/unistack-org/micro-client-http/v3"
|
||||
micro_api "github.com/unistack-org/micro/v3/api"
|
||||
micro_client "github.com/unistack-org/micro/v3/client"
|
||||
micro_server "github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
@@ -39,7 +34,6 @@ func (c *githubService) LookupUser(ctx context.Context, req *LookupUserReq, opts
|
||||
nopts := append(opts,
|
||||
micro_client_http.Method("GET"),
|
||||
micro_client_http.Path("/users/{username}"),
|
||||
micro_client_http.Body(""),
|
||||
micro_client_http.ErrorMap(errmap),
|
||||
)
|
||||
rsp := &LookupUserRsp{}
|
||||
@@ -64,31 +58,3 @@ type githubHandler struct {
|
||||
func (h *githubHandler) LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error {
|
||||
return h.GithubHandler.LookupUser(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func Register(r *mux.Router, h interface{}, eps []*micro_api.Endpoint) error {
|
||||
v := reflect.ValueOf(h)
|
||||
|
||||
methods := v.NumMethod()
|
||||
if methods < 1 {
|
||||
return fmt.Errorf("invalid handler specified: %#+v", h)
|
||||
}
|
||||
|
||||
for _, ep := range eps {
|
||||
idx := strings.Index(ep.Name, ".")
|
||||
if idx < 1 || len(ep.Name) <= idx {
|
||||
return fmt.Errorf("invalid api.Endpoint name: %s", ep.Name)
|
||||
}
|
||||
name := ep.Name[idx+1:]
|
||||
m := v.MethodByName(name)
|
||||
if !m.IsValid() || m.IsZero() {
|
||||
return fmt.Errorf("invalid handler, method %s not found", name)
|
||||
}
|
||||
|
||||
rh, ok := m.Interface().(func(http.ResponseWriter, *http.Request))
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid handler: %#+v", m.Interface())
|
||||
}
|
||||
r.HandleFunc(ep.Path[0], rh).Methods(ep.Method...).Name(ep.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user