use never protoc-gen-micro

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-19 12:50:35 +03:00
parent 48558b66ff
commit 3876ba5705
4 changed files with 3 additions and 50 deletions

View File

@ -2,6 +2,7 @@ syntax = "proto3";
package github; package github;
option go_package = "github.com//unistack-org/micro-tests/client/http/proto;pb"; option go_package = "github.com//unistack-org/micro-tests/client/http/proto;pb";
import "google/api/annotations.proto"; import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto"; import "protoc-gen-openapiv2/options/annotations.proto";
@ -13,28 +14,19 @@ service Github {
key: "default"; key: "default";
value: { value: {
description: "Error response"; description: "Error response";
schema: { schema: { json_schema: { ref: ".github.Error"; } }
json_schema: {
ref: ".github.Error";
}
}
} }
} }
}; };
option (google.api.http) = { option (google.api.http) = { get: "/users/{username}"; };
get: "/users/{username}";
}; };
}; };
};
message LookupUserReq { message LookupUserReq {
string username = 1; string username = 1;
}; };
message LookupUserRsp { message LookupUserRsp {
string name = 1; string name = 1;
}; };
message Error { message Error {
string message = 1; string message = 1;
}; };

View File

@ -5,13 +5,8 @@ package pb
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
"reflect"
"strings"
"github.com/gorilla/mux"
micro_client_http "github.com/unistack-org/micro-client-http/v3" 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_client "github.com/unistack-org/micro/v3/client"
micro_server "github.com/unistack-org/micro/v3/server" 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, nopts := append(opts,
micro_client_http.Method("GET"), micro_client_http.Method("GET"),
micro_client_http.Path("/users/{username}"), micro_client_http.Path("/users/{username}"),
micro_client_http.Body(""),
micro_client_http.ErrorMap(errmap), micro_client_http.ErrorMap(errmap),
) )
rsp := &LookupUserRsp{} rsp := &LookupUserRsp{}
@ -64,31 +58,3 @@ type githubHandler struct {
func (h *githubHandler) LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error { func (h *githubHandler) LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error {
return h.GithubHandler.LookupUser(ctx, req, rsp) 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
}

1
go.mod
View File

@ -5,7 +5,6 @@ go 1.15
require ( require (
github.com/golang/protobuf v1.4.3 github.com/golang/protobuf v1.4.3
github.com/google/uuid v1.1.5 github.com/google/uuid v1.1.5
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.1.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.1.0
github.com/opentracing/opentracing-go v1.2.0 github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.9.0 github.com/prometheus/client_golang v1.9.0

4
go.sum
View File

@ -237,8 +237,6 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
@ -524,8 +522,6 @@ github.com/unistack-org/micro-broker-memory/v3 v3.1.1 h1:cDBIh/dVxuh2EnzuRyUVCsw
github.com/unistack-org/micro-broker-memory/v3 v3.1.1/go.mod h1:lSFmkUtAlfsizywNOT+nNfpXeagM5+8tFDda3qFSPwY= github.com/unistack-org/micro-broker-memory/v3 v3.1.1/go.mod h1:lSFmkUtAlfsizywNOT+nNfpXeagM5+8tFDda3qFSPwY=
github.com/unistack-org/micro-client-grpc/v3 v3.1.1 h1:z0ic1qK3nRIPi30UQQTGJJReSA9K+Q33e8znYTcgtN4= github.com/unistack-org/micro-client-grpc/v3 v3.1.1 h1:z0ic1qK3nRIPi30UQQTGJJReSA9K+Q33e8znYTcgtN4=
github.com/unistack-org/micro-client-grpc/v3 v3.1.1/go.mod h1:mJ72LTougMlZ1jTRr0jS38JfK2MRo08ew4V8fpQFZMo= github.com/unistack-org/micro-client-grpc/v3 v3.1.1/go.mod h1:mJ72LTougMlZ1jTRr0jS38JfK2MRo08ew4V8fpQFZMo=
github.com/unistack-org/micro-client-http/v3 v3.1.1 h1:+gjRljMobCdeLB8aTo8hVIEQff6BpmAOrGxIQjqCTko=
github.com/unistack-org/micro-client-http/v3 v3.1.1/go.mod h1:Ra1QDLHVJxaIk+z+1rwHd5wzwdHRFaS8byOoShDqYgw=
github.com/unistack-org/micro-client-http/v3 v3.1.2 h1:Ipvgub65nNuX5iSb7Ehy0AZu92v6Xxz9iwMOs9YIOUI= github.com/unistack-org/micro-client-http/v3 v3.1.2 h1:Ipvgub65nNuX5iSb7Ehy0AZu92v6Xxz9iwMOs9YIOUI=
github.com/unistack-org/micro-client-http/v3 v3.1.2/go.mod h1:7tddLMx5wijKxjK3p1ikhzxKlBubBZ3vlPgPPhS0edc= github.com/unistack-org/micro-client-http/v3 v3.1.2/go.mod h1:7tddLMx5wijKxjK3p1ikhzxKlBubBZ3vlPgPPhS0edc=
github.com/unistack-org/micro-codec-grpc/v3 v3.1.1 h1:h+x6ny1UeMEqZWPx7vhkfczetnFh00lbCxdLl9Rr0EU= github.com/unistack-org/micro-codec-grpc/v3 v3.1.1 h1:h+x6ny1UeMEqZWPx7vhkfczetnFh00lbCxdLl9Rr0EU=