api add tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-10 10:18:42 +03:00
parent e7dc3c5fb3
commit 957c488cbe
10 changed files with 237 additions and 130 deletions

View File

@ -0,0 +1,40 @@
// +build ignore
package router
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/unistack-org/micro/v3/registry"
)
func TestStoreRegex(t *testing.T) {
t.Skip()
router, err := newRouter()
if err != nil {
t.Fatal(err)
}
router.store([]*registry.Service{
{
Name: "Foobar",
Version: "latest",
Endpoints: []*registry.Endpoint{
{
Name: "foo",
Metadata: map[string]string{
"endpoint": "FooEndpoint",
"description": "Some description",
"method": "POST",
"path": "^/foo/$",
"handler": "rpc",
},
},
},
Metadata: map[string]string{},
},
},
)
assert.Len(t, router.ceps["Foobar.foo"].pcreregs, 1)
}

View File

@ -1,5 +1,3 @@
// +build ignore
package router_test
import (
@ -11,22 +9,24 @@ import (
"testing"
"time"
rpc "github.com/unistack-org/micro-api-handler-rpc"
rregistry "github.com/unistack-org/micro-api-router-registry"
rstatic "github.com/unistack-org/micro-api-router-static"
bmemory "github.com/unistack-org/micro-broker-memory"
gcli "github.com/unistack-org/micro-client-grpc"
jsoncodec "github.com/unistack-org/micro-codec-json"
protocodec "github.com/unistack-org/micro-codec-proto"
rmemory "github.com/unistack-org/micro-registry-memory"
regRouter "github.com/unistack-org/micro-router-registry"
gsrv "github.com/unistack-org/micro-server-grpc"
pb "github.com/unistack-org/micro-tests/server/grpc/proto"
"github.com/unistack-org/micro/v3/api"
"github.com/unistack-org/micro/v3/api/handler"
"github.com/unistack-org/micro/v3/api/handler/rpc"
"github.com/unistack-org/micro/v3/api/router"
rregistry "github.com/unistack-org/micro/v3/api/router/registry"
rstatic "github.com/unistack-org/micro/v3/api/router/static"
"github.com/unistack-org/micro/v3/broker"
bmemory "github.com/unistack-org/micro/v3/broker/memory"
"github.com/unistack-org/micro/v3/client"
gcli "github.com/unistack-org/micro/v3/client/grpc"
rmemory "github.com/unistack-org/micro/v3/registry/memory"
rt "github.com/unistack-org/micro/v3/router"
regRouter "github.com/unistack-org/micro/v3/router/registry"
"github.com/unistack-org/micro/v3/server"
gsrv "github.com/unistack-org/micro/v3/server/grpc"
pb "github.com/unistack-org/micro/v3/server/grpc/proto"
)
// server is used to implement helloworld.GreeterServer.
@ -52,22 +52,42 @@ func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *
}
func initial(t *testing.T) (server.Server, client.Client) {
//logger.DefaultLogger = logger.NewLogger(logger.WithLevel(logger.TraceLevel))
r := rmemory.NewRegistry()
if err := r.Init(); err != nil {
t.Fatal(err)
}
b := bmemory.NewBroker(broker.Registry(r))
if err := b.Init(); err != nil {
t.Fatal(err)
}
// create a new client
s := gsrv.NewServer(
server.Codec("application/grpc+proto", protocodec.NewCodec()),
server.Codec("application/grpc+json", protocodec.NewCodec()),
server.Codec("application/json", jsoncodec.NewCodec()),
server.Name("foo"),
server.Broker(b),
server.Registry(r),
server.RegisterInterval(1*time.Second),
)
rtr := regRouter.NewRouter(
rt.Registry(r),
)
if err := rtr.Init(); err != nil {
t.Fatal(err)
}
// create a new server
c := gcli.NewClient(
client.Codec("application/grpc+proto", protocodec.NewCodec()),
client.Codec("application/grpc+json", protocodec.NewCodec()),
client.Codec("application/json", jsoncodec.NewCodec()),
client.Registry(r),
client.Router(rtr),
client.Broker(b),
)
@ -75,6 +95,10 @@ func initial(t *testing.T) (server.Server, client.Client) {
h := &testServer{}
pb.RegisterTestHandler(s, h)
if err := s.Init(); err != nil {
t.Fatalf("failed to init: %v", err)
}
if err := s.Start(); err != nil {
t.Fatalf("failed to start: %v", err)
}
@ -113,6 +137,10 @@ func TestRouterRegistryPcre(t *testing.T) {
router.WithHandler(rpc.Handler),
router.WithRegistry(s.Options().Registry),
)
if err := router.Init(); err != nil {
t.Fatal(err)
}
hrpc := rpc.NewHandler(
handler.WithClient(c),
handler.WithRouter(router),
@ -132,7 +160,7 @@ func TestRouterRegistryPcre(t *testing.T) {
defer hsrv.Close()
time.Sleep(1 * time.Second)
check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello TEST"}`)
check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello "}`)
}
func TestRouterStaticPcre(t *testing.T) {
@ -143,6 +171,9 @@ func TestRouterStaticPcre(t *testing.T) {
router.WithHandler(rpc.Handler),
router.WithRegistry(s.Options().Registry),
)
if err := router.Init(); err != nil {
t.Fatal(err)
}
err := router.Register(&api.Endpoint{
Name: "foo.Test.Call",

8
go.mod
View File

@ -9,6 +9,9 @@ require (
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/client_model v0.2.0
github.com/stretchr/testify v1.6.1
github.com/unistack-org/micro-api-handler-rpc v0.0.0-20210109162638-64670d8535df
github.com/unistack-org/micro-api-router-registry v0.0.0-20210110010133-d6468aa91d66
github.com/unistack-org/micro-api-router-static v0.0.0-20210109231342-6a822df8185c
github.com/unistack-org/micro-broker-http v0.0.0-20201125231853-bb4bd204b8c0
github.com/unistack-org/micro-broker-memory v0.0.2-0.20201105185131-5ff932308afd
github.com/unistack-org/micro-client-grpc v0.0.2-0.20201228123319-bbd07bb0914a
@ -19,13 +22,14 @@ require (
github.com/unistack-org/micro-codec-segmentio v0.0.0-20201220210027-bc88e5dad1c2
github.com/unistack-org/micro-config-env v0.0.0-20201219213431-afab7aa1d69f
github.com/unistack-org/micro-metrics-prometheus v0.0.2-0.20201125232532-93104a0ff374
github.com/unistack-org/micro-registry-memory v0.0.2-0.20201105195351-bd57ee0e4bd6
github.com/unistack-org/micro-registry-memory v0.0.2-0.20210110004413-c27422bc489a
github.com/unistack-org/micro-router-registry v0.0.2-0.20201105175056-773128885d9e
github.com/unistack-org/micro-server-grpc v0.0.3-0.20201228125110-b2aa849c1e7b
github.com/unistack-org/micro-server-http v0.0.2-0.20201125222045-54ee918b278c
github.com/unistack-org/micro-server-tcp v0.0.2-0.20201125222121-31fd93a07671
github.com/unistack-org/micro-wrapper-opentracing v0.0.1
github.com/unistack-org/micro/v3 v3.0.2-0.20201220205329-e6f870bda71a
github.com/unistack-org/micro/v3 v3.0.2-0.20210110005504-270ad1b88914
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d
google.golang.org/grpc v1.34.0
google.golang.org/protobuf v1.25.0
)

24
go.sum
View File

@ -104,6 +104,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/evanphx/json-patch/v5 v5.1.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/evanphx/json-patch/v5 v5.2.0 h1:8ozOH5xxoMYDt5/u+yMTsVXydVCbTORFnOOoq2lumco=
github.com/evanphx/json-patch/v5 v5.2.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
@ -126,8 +128,13 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.3/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -330,6 +337,7 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -416,6 +424,12 @@ github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLp
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
github.com/unistack-org/micro-api-handler-rpc v0.0.0-20210109162638-64670d8535df h1:DHlto3KT/EZ+rVQztapOvh07iWbF/8p2FFRxy0knmMY=
github.com/unistack-org/micro-api-handler-rpc v0.0.0-20210109162638-64670d8535df/go.mod h1:z1hfVzV132MuyGjUY+mqfiSkjZiFnfRTqCC87puYDF4=
github.com/unistack-org/micro-api-router-registry v0.0.0-20210110010133-d6468aa91d66 h1:FoCCu5zME0rvxmftdz69UA/KhoYNTEt3OCcd6g4eYvE=
github.com/unistack-org/micro-api-router-registry v0.0.0-20210110010133-d6468aa91d66/go.mod h1:yOm0OvGBKnSan5fgIrhHMZh0P3pHAEIJkjniZaRghc8=
github.com/unistack-org/micro-api-router-static v0.0.0-20210109231342-6a822df8185c h1:bRESfIXdXknwxm3Vu9d3fZv16sSQTuFUP6iNqBs1qmk=
github.com/unistack-org/micro-api-router-static v0.0.0-20210109231342-6a822df8185c/go.mod h1:X+ufm/HOyg3rFiyi9nmBam/azXw++Zk17F0Q/nuhwAg=
github.com/unistack-org/micro-broker-http v0.0.0-20201125231853-bb4bd204b8c0 h1:5jC+fK9XYUo8SnoVPVtGvYLMei6fuJuIM0NK07jcqdo=
github.com/unistack-org/micro-broker-http v0.0.0-20201125231853-bb4bd204b8c0/go.mod h1:WtKt1GCpw7WSbF83g1rg020u9uJiwF61c+dAHMLLfI0=
github.com/unistack-org/micro-broker-memory v0.0.2-0.20201105185131-5ff932308afd h1:LNMB1G3yZEI1zpX4SGodLqUfOw4Zan30rcpcvKTDMCI=
@ -447,8 +461,8 @@ github.com/unistack-org/micro-config-env v0.0.0-20201219213431-afab7aa1d69f h1:h
github.com/unistack-org/micro-config-env v0.0.0-20201219213431-afab7aa1d69f/go.mod h1:CZh4t6yk0ObPT6dRU3dzvtBpYLigXXZjbYsunGKylIc=
github.com/unistack-org/micro-metrics-prometheus v0.0.2-0.20201125232532-93104a0ff374 h1:5AJyrOi52tAW+3OLfTuan5LMD1SLFwHRTT3bMQb/5t8=
github.com/unistack-org/micro-metrics-prometheus v0.0.2-0.20201125232532-93104a0ff374/go.mod h1:08E+Tc4yyY9OBCeJRDZ5oYvuVr+MktOkxF+aL+svRMk=
github.com/unistack-org/micro-registry-memory v0.0.2-0.20201105195351-bd57ee0e4bd6 h1:5MH9y5Zn8OyVwD6XWyP2ejuktpqLHD1JOVYoOwYZ1mo=
github.com/unistack-org/micro-registry-memory v0.0.2-0.20201105195351-bd57ee0e4bd6/go.mod h1:0f9qV/bM07qO2sNuNnr3qOEozsYpmkTxuEgauWLWDec=
github.com/unistack-org/micro-registry-memory v0.0.2-0.20210110004413-c27422bc489a h1:fIu/yOwNzZcObCnA5rGZeHNgyoO7d3Hirj0JyStFO/s=
github.com/unistack-org/micro-registry-memory v0.0.2-0.20210110004413-c27422bc489a/go.mod h1:MbrzjodCgQwWtYG48wQj1gYF6gJELgFZV0p1+wofBVc=
github.com/unistack-org/micro-router-registry v0.0.2-0.20201105175056-773128885d9e h1:spzPFROFgxXCoggEv0dapiH3Hfp0x/HqQy4rimQ1rbU=
github.com/unistack-org/micro-router-registry v0.0.2-0.20201105175056-773128885d9e/go.mod h1:nvJqRLixa2UqbctfnMx1WJ6IJdPJQ9FheJnh+03QsXA=
github.com/unistack-org/micro-server-grpc v0.0.3-0.20201228125110-b2aa849c1e7b h1:reSC8zxP9mfNp+u8zIlUz9TGWm6onj7vAaIXRsUwffA=
@ -467,11 +481,15 @@ github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922103357-4c4fa00a5d94/go.m
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201105181805-e12754779912/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201105193505-8fa8afdfa4b4/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw=
github.com/unistack-org/micro/v3 v3.0.2-0.20201117210202-01e64cb0c0f3/go.mod h1:LYbzHigEudM10AbLZztVSX0Y4JWgj5nKIExil/99h6E=
github.com/unistack-org/micro/v3 v3.0.2-0.20201125221305-0d93b2c31c79/go.mod h1:RxbWu3Q2jWpw0er6CwX2BnGdIDfUZg/0c4bMxzAzaH0=
github.com/unistack-org/micro/v3 v3.0.2-0.20201219211529-b50855855b58/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/unistack-org/micro/v3 v3.0.2-0.20201220205329-e6f870bda71a h1:S3KGfUO9LttJMvakfFZgd1bLz8XY2Z7X0DYLdgDDhXY=
github.com/unistack-org/micro/v3 v3.0.2-0.20201220205329-e6f870bda71a/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/unistack-org/micro/v3 v3.0.2-0.20210109225421-8930c3fbb748 h1:tPXIO1QFi2DxPv8nsSACNKsydmToqHZ4x0xIZMvX9es=
github.com/unistack-org/micro/v3 v3.0.2-0.20210109225421-8930c3fbb748/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/unistack-org/micro/v3 v3.0.2-0.20210110005504-270ad1b88914 h1:dPr7zSJSTtio1GQrRUXHUQOA+xNe4vZJQ4t5LEsEibU=
github.com/unistack-org/micro/v3 v3.0.2-0.20210110005504-270ad1b88914/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=

View File

@ -1,3 +1,3 @@
package grpc
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=paths=source_relative:./proto proto/test.proto
//go:generate protoc -I./proto -I$GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.9.5/third_party/googleapis -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=paths=source_relative:./proto proto/test.proto

View File

@ -0,0 +1,52 @@
// Code generated by protoc-gen-micro
// source: test.proto
package helloworld
import (
"context"
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"
)
// NewTestEndpoints provides api endpoints metdata for Test service
func NewTestEndpoints() []*micro_api.Endpoint {
var endpoints []*micro_api.Endpoint
endpoint := &micro_api.Endpoint{
Name: "Test.Call",
Path: []string{"/api/v0/test/call/TEST"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
}
endpoints = append(endpoints, endpoint)
return endpoints
}
// TestService interface
type TestService interface {
Call(context.Context, *Request, ...micro_client.CallOption) (*Response, error)
}
// Micro server stuff
// TestHandler server handler
type TestHandler interface {
Call(context.Context, *Request, *Response) error
}
// RegisterTestHandler registers server handler
func RegisterTestHandler(s micro_server.Server, sh TestHandler, opts ...micro_server.HandlerOption) error {
type test interface {
Call(context.Context, *Request, *Response) error
}
type Test struct {
test
}
h := &testHandler{sh}
for _, endpoint := range NewTestEndpoints() {
opts = append(opts, micro_api.WithEndpoint(endpoint))
}
return s.Handle(s.NewHandler(&Test{h}, opts...))
}

View File

@ -0,0 +1,46 @@
// Code generated by protoc-gen-micro
// source: test.proto
package helloworld
import (
"context"
micro_client "github.com/unistack-org/micro/v3/client"
micro_server "github.com/unistack-org/micro/v3/server"
)
var (
_ micro_server.Option
_ micro_client.Option
)
type testService struct {
c micro_client.Client
name string
}
// Micro client stuff
// NewTestService create new service client
func NewTestService(name string, c micro_client.Client) TestService {
return &testService{c: c, name: name}
}
func (c *testService) Call(ctx context.Context, req *Request, opts ...micro_client.CallOption) (*Response, error) {
rsp := &Response{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
// Micro server stuff
type testHandler struct {
TestHandler
}
func (h *testHandler) Call(ctx context.Context, req *Request, rsp *Response) error {
return h.TestHandler.Call(ctx, req, rsp)
}

View File

@ -8,6 +8,7 @@ package helloworld
import (
proto "github.com/golang/protobuf/proto"
_ "google.golang.org/genproto/googleapis/api/annotations"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
@ -194,25 +195,29 @@ var File_test_proto protoreflect.FileDescriptor
var file_test_proto_rawDesc = []byte{
0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x22, 0x5d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x62,
0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x52,
0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x1e, 0x0a, 0x06, 0x42, 0x72, 0x6f, 0x6b, 0x65,
0x6e, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x22, 0x48, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x2a, 0x0a, 0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x18,
0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72,
0x6c, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65,
0x6e, 0x32, 0x3b, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x33, 0x0a, 0x04, 0x43, 0x61, 0x6c,
0x6c, 0x12, 0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f,
0x72, 0x6c, 0x64, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e,
0x5a, 0x0c, 0x2e, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x62, 0x72, 0x6f,
0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c,
0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x06, 0x62,
0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x1e, 0x0a, 0x06, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x12,
0x14, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x66, 0x69, 0x65, 0x6c, 0x64, 0x22, 0x48, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x6d, 0x73, 0x67, 0x12, 0x2a, 0x0a, 0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64,
0x2e, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x32,
0x5c, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x54, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12,
0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c,
0x64, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x21, 0x82, 0xd3, 0xe4, 0x93,
0x02, 0x1b, 0x22, 0x16, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x30, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x54, 0x45, 0x53, 0x54, 0x3a, 0x01, 0x2a, 0x42, 0x0e, 0x5a,
0x0c, 0x2e, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -1,92 +0,0 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: test.proto
package helloworld
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/unistack-org/micro/v3/api"
client "github.com/unistack-org/micro/v3/client"
server "github.com/unistack-org/micro/v3/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for Test service
func NewTestEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Test service
type TestService interface {
Call(ctx context.Context, req *Request, opts ...client.CallOption) (*Response, error)
}
type testService struct {
c client.Client
name string
}
func NewTestService(name string, c client.Client) TestService {
return &testService{
c: c,
name: name,
}
}
func (c *testService) Call(ctx context.Context, req *Request, opts ...client.CallOption) (*Response, error) {
rsp := &Response{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
// Server API for Test service
type TestHandler interface {
Call(context.Context, *Request, *Response) error
}
func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *Request, rsp *Response) error
}
type Test struct {
test
}
h := &testHandler{hdlr}
return s.Handle(s.NewHandler(&Test{h}, opts...))
}
type testHandler struct {
TestHandler
}
func (h *testHandler) Call(ctx context.Context, req *Request, rsp *Response) error {
return h.TestHandler.Call(ctx, req, rsp)
}

View File

@ -3,9 +3,12 @@ syntax = "proto3";
package helloworld;
option go_package = ".;helloworld";
import "google/api/annotations.proto";
service Test {
rpc Call(Request) returns (Response) {}
rpc Call(Request) returns (Response) {
option (google.api.http) = { post: "/api/v0/test/call/TEST"; body: "*"; };
};
}
message Request {