Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-12-11 02:00:29 +03:00
parent e7e1ff15f4
commit 1aa324c17f
63 changed files with 2488 additions and 1165 deletions

View File

@ -1,615 +0,0 @@
package segmentio_test
import (
"context"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/segmentio/kafka-go"
segmentio "go.unistack.org/micro-broker-segmentio/v3"
victoriameter "go.unistack.org/micro-meter-victoriametrics/v3"
https "go.unistack.org/micro-server-http/v3"
meterhandler "go.unistack.org/micro-server-http/v3/handler/meter"
"go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/meter"
"go.unistack.org/micro/v3/server"
)
type lg struct{}
func (l *lg) Printf(format string, args ...interface{}) {
// logger.Infof(context.Background(), format, args...)
}
var bm = &broker.Message{
Header: map[string]string{"hkey": "hval"},
Body: []byte(`"body"`),
}
func TestConsumerGroup(t *testing.T) {
topic := "test_topic"
if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 {
return
// t.Skip()
}
if err := logger.DefaultLogger.Init(logger.WithLevel(logger.TraceLevel)); err != nil {
t.Fatal(err)
}
ctx := context.Background()
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
} else {
addrs = strings.Split(addr, ",")
}
meter.DefaultMeter = victoriameter.NewMeter()
s := https.NewServer(server.Context(ctx), server.Address("127.0.0.1:0"), server.Codec("text/plain", codec.NewCodec()))
if err := s.Init(); err != nil {
t.Fatal(err)
}
if err := meterhandler.RegisterMeterServiceServer(s, meterhandler.NewHandler()); err != nil {
t.Fatal(err)
}
if err := s.Start(); err != nil {
t.Fatal(err)
}
defer func() {
if err := s.Stop(); err != nil {
t.Fatal(err)
}
}()
segmentio.DefaultWriterConfig.Async = true
segmentio.DefaultWriterConfig.BatchTimeout = 1 * time.Second
segmentio.DefaultWriterConfig.RequiredAcks = int(kafka.RequireAll)
segmentio.DefaultReaderConfig.StartOffset = kafka.FirstOffset
segmentio.DefaultReaderConfig.MinBytes = 1024 * 10 // 10 kb
segmentio.DefaultReaderConfig.MaxBytes = 1024 * 1024 * 20 // 20 Mb
segmentio.DefaultReaderConfig.MaxWait = 20 * time.Second // 20s
segmentio.DefaultReaderConfig.QueueCapacity = 500
segmentio.DefaultReaderConfig.ReadBackoffMin = 2 * time.Second
segmentio.DefaultReaderConfig.ReadBackoffMax = 5 * time.Second
segmentio.DefaultReaderConfig.Logger = &lg{}
segmentio.DefaultReaderConfig.CommitInterval = 1 * time.Second
brk := segmentio.NewBroker(broker.Context(ctx), broker.Addrs(addrs...), segmentio.StatsInterval(5*time.Second),
segmentio.ClientID("test_sub"),
)
t.Logf("init")
if err := brk.Init(); err != nil {
t.Fatal(err)
}
t.Logf("connect")
if err := brk.Connect(ctx); err != nil {
t.Fatal(err)
}
defer func() {
t.Logf("disconnect")
if err := brk.Disconnect(ctx); err != nil {
t.Fatal(err)
}
}()
fmt.Printf("prefill topic\n")
go func() {
for i := 0; i < 900000; i++ {
if err := brk.Publish(ctx, topic, bm); err != nil {
t.Fatal(err)
}
// log.Printf("publish %d", i)
time.Sleep(600 * time.Millisecond)
}
}()
fmt.Printf("prefill complete\n")
var cnt uint64
var wait atomic.Value
wait.Store(true)
fn := func(msg broker.Event) error {
if wait.Load().(bool) {
wait.Store(false)
}
atomic.AddUint64(&cnt, 1)
fmt.Printf("processing mesage")
return msg.Ack()
}
sub1, err := brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true), broker.SubscribeAutoAck(true))
if err != nil {
t.Fatal(err)
}
defer sub1.Unsubscribe(ctx)
sub2, err := brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true), broker.SubscribeAutoAck(true))
if err != nil {
t.Fatal(err)
}
defer sub2.Unsubscribe(ctx)
fmt.Printf("wait for ready\n")
for {
if !wait.Load().(bool) {
break
}
time.Sleep(1 * time.Second)
}
/*
time.Sleep(5 * time.Second)
fmt.Printf("unsub\n")
if err := sub1.Unsubscribe(ctx); err != nil {
t.Fatal(err)
}
time.Sleep(9 * time.Second)
sub1, err = brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true), broker.SubscribeAutoAck(true))
if err != nil {
t.Fatal(err)
}
*/
/*
t1 := time.NewTicker(10 * time.Second)
defer t1.Stop()
t2 := time.NewTicker(30 * time.Second)
defer t2.Stop()
for {
select {
case <-t1.C:
fmt.Printf("unsub from sub2\n")
if err := sub2.Unsubscribe(ctx); err != nil {
t.Fatal(err)
}
fmt.Printf("sub1\n")
sub1, err = brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true), broker.SubscribeAutoAck(true))
if err != nil {
t.Fatal(err)
}
case <-t2.C:
fmt.Printf("unsub from sub1\n")
if err := sub1.Unsubscribe(ctx); err != nil {
t.Fatal(err)
}
fmt.Printf("sub2\n")
sub2, err = brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true), broker.SubscribeAutoAck(true))
if err != nil {
t.Fatal(err)
}
}
}
*/
select {}
}
func TestSub(t *testing.T) {
topic := "test_topic"
if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 {
return
// t.Skip()
}
if err := logger.DefaultLogger.Init(logger.WithLevel(logger.ErrorLevel)); err != nil {
t.Fatal(err)
}
ctx := context.Background()
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
} else {
addrs = strings.Split(addr, ",")
}
meter.DefaultMeter = victoriameter.NewMeter()
s := https.NewServer(server.Context(ctx), server.Address("127.0.0.1:0"), server.Codec("text/plain", codec.NewCodec()))
if err := s.Init(); err != nil {
t.Fatal(err)
}
if err := meterhandler.RegisterMeterServiceServer(s, meterhandler.NewHandler()); err != nil {
t.Fatal(err)
}
if err := s.Start(); err != nil {
t.Fatal(err)
}
defer func() {
if err := s.Stop(); err != nil {
t.Fatal(err)
}
}()
segmentio.DefaultWriterConfig.Async = true
segmentio.DefaultWriterConfig.BatchTimeout = 1 * time.Second
segmentio.DefaultWriterConfig.RequiredAcks = int(kafka.RequireAll)
segmentio.DefaultReaderConfig.StartOffset = kafka.FirstOffset
segmentio.DefaultReaderConfig.MinBytes = 1024 * 10 // 10 kb
segmentio.DefaultReaderConfig.MaxBytes = 1024 * 1024 * 20 // 20 Mb
segmentio.DefaultReaderConfig.MaxWait = 20 * time.Second // 20s
segmentio.DefaultReaderConfig.QueueCapacity = 500
segmentio.DefaultReaderConfig.ReadBackoffMin = 2 * time.Second
segmentio.DefaultReaderConfig.ReadBackoffMax = 5 * time.Second
segmentio.DefaultReaderConfig.Logger = &lg{}
segmentio.DefaultReaderConfig.CommitInterval = 1 * time.Second
brk := segmentio.NewBroker(broker.Context(ctx), broker.Addrs(addrs...), segmentio.StatsInterval(5*time.Second),
segmentio.ClientID("test_sub"),
)
t.Logf("init")
if err := brk.Init(); err != nil {
t.Fatal(err)
}
t.Logf("connect")
if err := brk.Connect(ctx); err != nil {
t.Fatal(err)
}
defer func() {
t.Logf("disconnect")
if err := brk.Disconnect(ctx); err != nil {
t.Fatal(err)
}
}()
fmt.Printf("prefill topic\n")
go func() {
for i := 0; i < 900000; i++ {
if err := brk.Publish(ctx, topic, bm); err != nil {
t.Fatal(err)
}
log.Printf("publish %d", i)
// time.Sleep(1 * time.Second)
}
}()
fmt.Printf("prefill complete\n")
var cnt uint64
var wait atomic.Value
wait.Store(true)
done := make(chan struct{})
fn := func(msg broker.Event) error {
if wait.Load().(bool) {
wait.Store(false)
fmt.Printf("done ready\n")
close(done)
}
atomic.AddUint64(&cnt, 1)
return msg.Ack()
}
sub, err := brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true))
if err != nil {
t.Fatal(err)
}
fmt.Printf("wait for ready\n")
<-done
fmt.Printf("wait for bench\n")
fmt.Printf("start %s\n", time.Now().String())
<-time.After(20 * time.Second)
fmt.Printf("stop %s\n", time.Now().String())
rcnt := atomic.LoadUint64(&cnt)
req, err := http.NewRequest(http.MethodGet, "http://"+s.Options().Address+"/metrics", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Add("Content-Type", "text/plain")
rsp, err := (&http.Client{}).Do(req)
if err != nil {
t.Fatal(err)
}
defer rsp.Body.Close()
buf, err := io.ReadAll(rsp.Body)
if err != nil {
t.Fatal(err)
}
fmt.Printf("unsub\n")
if err := sub.Unsubscribe(ctx); err != nil {
t.Fatal(err)
}
t.Logf("metrics: \n%s\n", buf)
t.Logf("mesage count %d\n", rcnt)
}
func BenchmarkPub(b *testing.B) {
if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 {
b.Skip()
}
if err := logger.DefaultLogger.Init(logger.WithLevel(logger.TraceLevel)); err != nil {
b.Fatal(err)
}
ctx := context.Background()
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
} else {
addrs = strings.Split(addr, ",")
}
meter.DefaultMeter = victoriameter.NewMeter()
s := https.NewServer(server.Context(ctx), server.Address("127.0.0.1:0"), server.Codec("text/plain", codec.NewCodec()))
if err := s.Init(); err != nil {
b.Fatal(err)
}
if err := meterhandler.RegisterMeterServiceServer(s, meterhandler.NewHandler()); err != nil {
b.Fatal(err)
}
if err := s.Start(); err != nil {
b.Fatal(err)
}
defer func() {
if err := s.Stop(); err != nil {
b.Fatal(err)
}
}()
segmentio.DefaultWriterConfig.Async = false
segmentio.DefaultWriterConfig.BatchTimeout = 1 * time.Second
segmentio.DefaultWriterConfig.RequiredAcks = int(kafka.RequireAll)
fn := func(msgs []kafka.Message, err error) {
if err != nil {
b.Logf("err %v", err)
}
}
brk := segmentio.NewBroker(broker.Context(ctx), broker.Addrs(addrs...), segmentio.StatsInterval(1*time.Second),
segmentio.WriterCompletionFunc(fn))
b.Logf("init")
if err := brk.Init(); err != nil {
b.Fatal(err)
}
b.Logf("connect")
if err := brk.Connect(ctx); err != nil {
b.Fatal(err)
}
defer func() {
b.Logf("disconnect")
if err := brk.Disconnect(ctx); err != nil {
b.Fatal(err)
}
}()
cnt := 0
b.ResetTimer()
for n := 0; n < b.N; n++ {
if err := brk.Publish(ctx, "test_topic", bm); err != nil {
b.Fatal(err)
}
cnt++
}
req, err := http.NewRequest(http.MethodGet, "http://"+s.Options().Address+"/metrics", nil)
if err != nil {
b.Fatal(err)
}
req.Header.Add("Content-Type", "text/plain")
rsp, err := (&http.Client{}).Do(req)
if err != nil {
b.Fatal(err)
}
defer rsp.Body.Close()
buf, err := io.ReadAll(rsp.Body)
if err != nil {
b.Fatal(err)
}
b.Logf("metrics: \n%s\n", buf)
b.Logf("mesage count %d\n", cnt)
}
func BenchmarkPubSub(b *testing.B) {
b.Skip()
ctx := context.Background()
topic := "test_topic"
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
} else {
addrs = strings.Split(addr, ",")
}
segmentio.DefaultWriterConfig.Async = true
segmentio.DefaultWriterConfig.BatchTimeout = 1 * time.Second
segmentio.DefaultReaderConfig.CommitInterval = 2 * time.Second
brk := segmentio.NewBroker(broker.Context(ctx), broker.Addrs(addrs...), segmentio.StatsInterval(1*time.Minute))
if err := brk.Init(); err != nil {
b.Fatal(err)
}
if err := brk.Connect(ctx); err != nil {
b.Fatal(err)
}
defer func() {
if err := brk.Disconnect(ctx); err != nil {
b.Fatal(err)
}
}()
wait := true
var cnt uint64
fn := func(msg broker.Event) error {
if wait {
wait = false
}
atomic.AddUint64(&cnt, 1)
return msg.Ack()
}
if err := brk.Publish(ctx, topic, bm); err != nil {
b.Fatal(err)
}
sub, err := brk.Subscribe(ctx, topic, fn, broker.SubscribeGroup("test"), broker.SubscribeBodyOnly(true))
if err != nil {
b.Fatal(err)
}
defer func() {
if err := sub.Unsubscribe(ctx); err != nil {
b.Fatal(err)
}
}()
for {
if !wait {
break
}
time.Sleep(1 * time.Second)
}
b.ResetTimer()
var result error
sent := uint64(0)
for n := 0; n < b.N; n++ {
if err := brk.Publish(ctx, topic, bm); err != nil {
b.Fatal(err)
} else {
result = err
}
sent++
}
b.Logf("publish done")
for {
c := atomic.LoadUint64(&cnt)
if c >= sent {
break
}
fmt.Printf("c %d seen %d\n", c, sent)
time.Sleep(1 * time.Second)
}
_ = result
fmt.Printf("c %d seen %d\n", atomic.LoadUint64(&cnt), sent)
}
func TestPubSub(t *testing.T) {
if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 {
return
// t.Skip()
}
if err := logger.DefaultLogger.Init(logger.WithLevel(logger.ErrorLevel)); err != nil {
t.Fatal(err)
}
ctx := context.Background()
var addrs []string
if addr := os.Getenv("BROKER_ADDRS"); len(addr) == 0 {
addrs = []string{"127.0.0.1:9092"}
} else {
addrs = strings.Split(addr, ",")
}
meter.DefaultMeter = victoriameter.NewMeter()
s := https.NewServer(server.Context(ctx), server.Address("127.0.0.1:0"), server.Codec("text/plain", codec.NewCodec()))
if err := s.Init(); err != nil {
t.Fatal(err)
}
if err := meterhandler.RegisterMeterServiceServer(s, meterhandler.NewHandler()); err != nil {
t.Fatal(err)
}
if err := s.Start(); err != nil {
t.Fatal(err)
}
defer func() {
if err := s.Stop(); err != nil {
t.Fatal(err)
}
}()
b := segmentio.NewBroker(broker.Context(ctx), broker.Addrs(addrs...), segmentio.StatsInterval(500*time.Millisecond),
segmentio.ClientID("test_pubsub"))
t.Logf("init")
if err := b.Init(); err != nil {
t.Fatal(err)
}
t.Logf("connect")
if err := b.Connect(ctx); err != nil {
t.Fatal(err)
}
defer func() {
t.Logf("disconnect")
if err := b.Disconnect(ctx); err != nil {
t.Fatal(err)
}
}()
wait := true
fn := func(msg broker.Event) error {
wait = false
return msg.Ack()
}
t.Logf("subscribe")
sub, err := b.Subscribe(ctx, "test_topic", fn, broker.SubscribeGroup("test"))
if err != nil {
t.Fatal(err)
}
defer func() {
t.Logf("unsubscribe")
if err := sub.Unsubscribe(ctx); err != nil {
t.Fatal(err)
}
}()
if err := b.Publish(ctx, "test_topic", bm); err != nil {
t.Fatal(err)
}
for {
if !wait {
break
}
time.Sleep(1 * time.Second)
}
req, err := http.NewRequest(http.MethodGet, "http://"+s.Options().Address+"/metrics", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Add("Content-Type", "text/plain")
rsp, err := (&http.Client{}).Do(req)
if err != nil {
t.Fatal(err)
}
defer rsp.Body.Close()
buf, err := io.ReadAll(rsp.Body)
if err != nil {
t.Fatal(err)
}
t.Logf("metrics: \n%s\n", buf)
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
// protoc-gen-go-drpc version: v0.0.32
// protoc-gen-go-drpc version: v0.0.34
// source: test.proto
package pb

View File

@ -1,23 +1,19 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
TestServiceName = "TestService"
)
var (
TestServiceServerEndpoints = []v3.EndpointMetadata{}
)
type TestServiceClient interface {
Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)

View File

@ -1,12 +1,11 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
)
@ -60,6 +59,5 @@ func RegisterTestServiceServer(s server.Server, sh TestServiceServer, opts ...se
}
h := &testServiceServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v3.HandlerEndpoints(TestServiceServerEndpoints))
return s.Handle(s.NewHandler(&TestService{h}, append(nopts, opts...)...))
}

View File

@ -1,14 +1,13 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package helloworld
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/client/grpc/proto"
client "go.unistack.org/micro/v3/client"
metadata "go.unistack.org/micro/v3/metadata"
@ -17,9 +16,6 @@ import (
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{}
)
type TestClient interface {
Call(ctx context.Context, req *proto.Request, opts ...client.CallOption) (*proto.Response, error)

View File

@ -1,12 +1,11 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package helloworld
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/client/grpc/proto"
client "go.unistack.org/micro/v3/client"
metadata "go.unistack.org/micro/v3/metadata"
@ -18,7 +17,7 @@ type testClient struct {
name string
}
func NewTestClient(name string, c client.Client) TestClient {
func NewTestClient(name string, c client.Client) proto.TestClient {
return &testClient{c: c, name: name}
}
@ -80,7 +79,7 @@ func (s *testClientStream) Recv() (*proto.Response, error) {
}
type testServer struct {
TestServer
proto.TestServer
}
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
@ -123,7 +122,7 @@ func (s *testStreamStream) Recv() (*proto.Request, error) {
return msg, nil
}
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
Stream(ctx context.Context, stream server.Stream) error
@ -133,6 +132,5 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp
}
h := &testServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package helloworld

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v3.21.12
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.3
// source: test.proto
package helloworld
@ -15,8 +15,8 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Test_Call_FullMethodName = "/helloworld.Test/Call"
@ -28,7 +28,7 @@ const (
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type TestClient interface {
Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
Stream(ctx context.Context, opts ...grpc.CallOption) (Test_StreamClient, error)
Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error)
}
type testClient struct {
@ -40,65 +40,52 @@ func NewTestClient(cc grpc.ClientConnInterface) TestClient {
}
func (c *testClient) Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testClient) Stream(ctx context.Context, opts ...grpc.CallOption) (Test_StreamClient, error) {
stream, err := c.cc.NewStream(ctx, &Test_ServiceDesc.Streams[0], Test_Stream_FullMethodName, opts...)
func (c *testClient) Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &Test_ServiceDesc.Streams[0], Test_Stream_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &testStreamClient{stream}
x := &grpc.GenericClientStream[Request, Response]{ClientStream: stream}
return x, nil
}
type Test_StreamClient interface {
Send(*Request) error
Recv() (*Response, error)
grpc.ClientStream
}
type testStreamClient struct {
grpc.ClientStream
}
func (x *testStreamClient) Send(m *Request) error {
return x.ClientStream.SendMsg(m)
}
func (x *testStreamClient) Recv() (*Response, error) {
m := new(Response)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type Test_StreamClient = grpc.BidiStreamingClient[Request, Response]
// TestServer is the server API for Test service.
// All implementations must embed UnimplementedTestServer
// for forward compatibility
// for forward compatibility.
type TestServer interface {
Call(context.Context, *Request) (*Response, error)
Stream(Test_StreamServer) error
Stream(grpc.BidiStreamingServer[Request, Response]) error
mustEmbedUnimplementedTestServer()
}
// UnimplementedTestServer must be embedded to have forward compatible implementations.
type UnimplementedTestServer struct {
}
// UnimplementedTestServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTestServer struct{}
func (UnimplementedTestServer) Call(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (UnimplementedTestServer) Stream(Test_StreamServer) error {
func (UnimplementedTestServer) Stream(grpc.BidiStreamingServer[Request, Response]) error {
return status.Errorf(codes.Unimplemented, "method Stream not implemented")
}
func (UnimplementedTestServer) mustEmbedUnimplementedTestServer() {}
func (UnimplementedTestServer) testEmbeddedByValue() {}
// UnsafeTestServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TestServer will
@ -108,6 +95,13 @@ type UnsafeTestServer interface {
}
func RegisterTestServer(s grpc.ServiceRegistrar, srv TestServer) {
// If the following call pancis, it indicates UnimplementedTestServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Test_ServiceDesc, srv)
}
@ -130,30 +124,11 @@ func _Test_Call_Handler(srv interface{}, ctx context.Context, dec func(interface
}
func _Test_Stream_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServer).Stream(&testStreamServer{stream})
return srv.(TestServer).Stream(&grpc.GenericServerStream[Request, Response]{ServerStream: stream})
}
type Test_StreamServer interface {
Send(*Response) error
Recv() (*Request, error)
grpc.ServerStream
}
type testStreamServer struct {
grpc.ServerStream
}
func (x *testStreamServer) Send(m *Response) error {
return x.ServerStream.SendMsg(m)
}
func (x *testStreamServer) Recv() (*Request, error) {
m := new(Request)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type Test_StreamServer = grpc.BidiStreamingServer[Request, Response]
// Test_ServiceDesc is the grpc.ServiceDesc for Test service.
// It's only intended for direct use with grpc.RegisterService,

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: github.proto
package pb

View File

@ -1,38 +1,19 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: github.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
GithubName = "Github"
)
var (
GithubServerEndpoints = []v3.EndpointMetadata{
{
Name: "Github.LookupUser",
Path: "/users/{username}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "Github.LookupUserWithoutPath",
Path: "/{username}",
Method: "GET",
Body: "",
Stream: false,
},
}
)
type GithubClient interface {
LookupUser(ctx context.Context, req *LookupUserReq, opts ...client.CallOption) (*LookupUserRsp, error)

View File

@ -1,18 +1,37 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: github.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-client-http/v3"
v31 "go.unistack.org/micro-server-http/v3"
v31 "go.unistack.org/micro-client-http/v3"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
http "net/http"
)
var (
GithubServerEndpoints = []v3.EndpointMetadata{
{
Name: "Github.LookupUser",
Path: "/users/{username}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "Github.LookupUserWithoutPath",
Path: "/{username}",
Method: "GET",
Body: "",
Stream: false,
},
}
)
type githubClient struct {
c client.Client
name string
@ -26,11 +45,11 @@ func (c *githubClient) LookupUser(ctx context.Context, req *LookupUserReq, opts
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/users/{username}"),
v31.Method(http.MethodGet),
v31.Path("/users/{username}"),
)
rsp := &LookupUserRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Github.LookupUser", req), rsp, opts...)
@ -44,11 +63,11 @@ func (c *githubClient) LookupUserWithoutPath(ctx context.Context, req *LookupUse
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/{username}"),
v31.Method(http.MethodGet),
v31.Path("/{username}"),
)
rsp := &LookupUserRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Github.LookupUserWithoutPath", req), rsp, opts...)
@ -80,6 +99,6 @@ func RegisterGithubServer(s server.Server, sh GithubServer, opts ...server.Handl
}
h := &githubServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(GithubServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(GithubServerEndpoints))
return s.Handle(s.NewHandler(&Github{h}, append(nopts, opts...)...))
}

View File

@ -0,0 +1,17 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.4
package pb
import (
protojson "google.golang.org/protobuf/encoding/protojson"
)
var (
marshaler = protojson.MarshalOptions{}
)
func (m *Error) Error() string {
buf, _ := marshaler.Marshal(m)
return string(buf)
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb

View File

@ -1,14 +1,13 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
codec "go.unistack.org/micro/v3/codec"
)
@ -16,9 +15,6 @@ import (
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{}
)
type TestClient interface {
Call(ctx context.Context, req *codec.Frame, opts ...client.CallOption) (*codec.Frame, error)

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
@ -13,6 +13,10 @@ import (
server "go.unistack.org/micro/v3/server"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{}
)
type testClient struct {
c client.Client
name string

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb

View File

@ -1,23 +1,19 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{}
)
type TestClient interface {
Call(ctx context.Context, req *Request, opts ...client.CallOption) (*Response, error)

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
@ -12,6 +12,10 @@ import (
server "go.unistack.org/micro/v3/server"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{}
)
type testClient struct {
c client.Client
name string

View File

@ -0,0 +1,17 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.4
package pb
import (
protojson "google.golang.org/protobuf/encoding/protojson"
)
var (
marshaler = protojson.MarshalOptions{}
)
func (m *Error) Error() string {
buf, _ := marshaler.Marshal(m)
return string(buf)
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb

View File

@ -1,52 +1,19 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
TestServiceName = "TestService"
)
var (
TestServiceServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestService.LookupUser",
Path: "/v1/user/{name}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UpdateUser",
Path: "/v1/user/{name}",
Method: "PUT",
Body: "*",
Stream: false,
},
{
Name: "TestService.DeleteUser",
Path: "/v1/user/{name}",
Method: "DELETE",
Body: "",
Stream: false,
},
{
Name: "TestService.MailUser",
Path: "/v1/user/{name}/mail",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestServiceClient interface {
LookupUser(ctx context.Context, req *LookupUserReq, opts ...client.CallOption) (*LookupUserRsp, error)

View File

@ -1,19 +1,52 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-client-http/v3"
v31 "go.unistack.org/micro-server-http/v3"
v31 "go.unistack.org/micro-client-http/v3"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
http "net/http"
time "time"
)
var (
TestServiceServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestService.LookupUser",
Path: "/v1/user/{name}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UpdateUser",
Path: "/v1/user/{name}",
Method: "PUT",
Body: "*",
Stream: false,
},
{
Name: "TestService.DeleteUser",
Path: "/v1/user/{name}",
Method: "DELETE",
Body: "",
Stream: false,
},
{
Name: "TestService.MailUser",
Path: "/v1/user/{name}/mail",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type testServiceClient struct {
c client.Client
name string
@ -27,11 +60,11 @@ func (c *testServiceClient) LookupUser(ctx context.Context, req *LookupUserReq,
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/v1/user/{name}"),
v31.Method(http.MethodGet),
v31.Path("/v1/user/{name}"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -47,12 +80,12 @@ func (c *testServiceClient) UpdateUser(ctx context.Context, req *UpdateUserReq,
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPut),
v3.Path("/v1/user/{name}"),
v3.Body("*"),
v31.Method(http.MethodPut),
v31.Path("/v1/user/{name}"),
v31.Body("*"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -68,11 +101,11 @@ func (c *testServiceClient) DeleteUser(ctx context.Context, req *DeleteUserReq,
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodDelete),
v3.Path("/v1/user/{name}"),
v31.Method(http.MethodDelete),
v31.Path("/v1/user/{name}"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -88,12 +121,12 @@ func (c *testServiceClient) MailUser(ctx context.Context, req *MailUserReq, opts
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/user/{name}/mail"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/user/{name}/mail"),
v31.Body("*"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -153,6 +186,6 @@ func RegisterTestServiceServer(s server.Server, sh TestServiceServer, opts ...se
}
h := &testServiceServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(TestServiceServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(TestServiceServerEndpoints))
return s.Handle(s.NewHandler(&TestService{h}, append(nopts, opts...)...))
}

127
go.mod
View File

@ -1,12 +1,15 @@
module go.unistack.org/micro-tests
go 1.19
go 1.22.7
toolchain go1.23.4
require (
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/VictoriaMetrics/metrics v1.23.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
@ -15,65 +18,79 @@ require (
github.com/hashicorp/vault/api v1.9.0 // indirect
github.com/jmoiron/sqlx v1.3.5
github.com/opentracing/opentracing-go v1.2.0
github.com/segmentio/kafka-go v0.4.39
github.com/stretchr/testify v1.8.1
github.com/twmb/franz-go v1.12.1
github.com/segmentio/kafka-go v0.4.47
github.com/stretchr/testify v1.10.0
github.com/twmb/franz-go v1.18.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/zeebo/errs v1.3.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
github.com/zeebo/errs v1.4.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.unistack.org/micro-broker-kgo/v3 v3.8.3
go.unistack.org/micro-broker-segmentio/v3 v3.8.0
go.unistack.org/micro-client-grpc/v3 v3.10.0
go.unistack.org/micro-client-http/v3 v3.9.0
go.unistack.org/micro-client-http/v3 v3.9.14
go.unistack.org/micro-codec-grpc/v3 v3.10.0
go.unistack.org/micro-codec-json/v3 v3.10.0
go.unistack.org/micro-codec-jsonpb/v3 v3.10.0
go.unistack.org/micro-codec-proto/v3 v3.10.0
go.unistack.org/micro-codec-segmentio/v3 v3.10.0
go.unistack.org/micro-codec-urlencode/v3 v3.10.0
go.unistack.org/micro-codec-xml/v3 v3.10.0
go.unistack.org/micro-config-consul/v3 v3.8.2
go.unistack.org/micro-config-env/v3 v3.8.3
go.unistack.org/micro-config-vault/v3 v3.8.4
go.unistack.org/micro-meter-prometheus/v3 v3.8.4
go.unistack.org/micro-meter-victoriametrics/v3 v3.8.6
go.unistack.org/micro-proto/v3 v3.3.1
go.unistack.org/micro-proto/v3 v3.4.1
go.unistack.org/micro-router-register/v3 v3.9.0
go.unistack.org/micro-server-grpc/v3 v3.10.3
go.unistack.org/micro-server-http/v3 v3.10.12
go.unistack.org/micro-server-http/v4 v4.0.2
go.unistack.org/micro-server-tcp/v3 v3.10.0
go.unistack.org/micro-tracer-opentracing/v3 v3.10.1
go.unistack.org/micro-wrapper-recovery/v3 v3.8.3
go.unistack.org/micro-wrapper-sql/v3 v3.10.3
go.unistack.org/micro/v3 v3.10.18
golang.org/x/crypto v0.7.0 // indirect
go.unistack.org/micro/v3 v3.11.14
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 // indirect
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.68.1
google.golang.org/protobuf v1.35.2
modernc.org/sqlite v1.20.3
storj.io/drpc v0.0.32
storj.io/drpc v0.0.34
)
require (
gitlab.mtsbank.ru/service-platform/framework/framework-modules/server-grpc v1.3.0
gitlab.mtsbank.ru/service-platform/framework/mtsbf v1.23.2
go.unistack.org/micro-client-mock/v3 v3.0.1
golang.org/x/net v0.8.0
go.unistack.org/micro-server-http/v3 v3.11.37
go.unistack.org/micro/v4 v4.0.1
golang.org/x/net v0.32.0
)
require (
dario.cat/mergo v1.0.1 // indirect
github.com/KimMachineGun/automemlimit v0.6.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cilium/ebpf v0.16.0 // indirect
github.com/containerd/cgroups/v3 v3.0.4 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/consul/api v1.19.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.7.0 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/consul/api v1.20.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v1.1.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
@ -81,34 +98,60 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/instana/go-sensor v1.66.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/looplab/fsm v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.41.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/encoding v0.3.6 // indirect
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.4.0 // indirect
github.com/segmentio/encoding v0.4.1 // indirect
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/twmb/franz-go/pkg/kadm v1.14.0 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.9.0 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/broker-kgo v0.5.0 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/broker-segmentio v0.3.1 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/codec-bytes v0.2.0 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/codec-proto v0.2.0 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/metrics-prometheus v0.1.1 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/micro-proto v0.0.1 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/micro-tracer-instana v0.0.11 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/micro-tracer-opentracing v0.0.9 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/prommeter v0.1.6 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/store-redis v1.3.1 // indirect
gitlab.mtsbank.ru/service-platform/framework/framework-modules/wrapper-opentracing v1.2.2 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.unistack.org/micro-proto/v4 v4.0.0 // indirect
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
@ -116,8 +159,8 @@ require (
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
modernc.org/token v1.1.0 // indirect
)

962
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -9,22 +9,15 @@ import (
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/meter"
"go.unistack.org/micro/v3/meter/wrapper"
)
func TestWrapper(t *testing.T) {
m := prometheus.NewMeter() // meter.Labels("test_key", "test_val"))
w := wrapper.NewClientWrapper(
wrapper.ServiceName("svc1"),
wrapper.ServiceVersion("0.0.1"),
wrapper.ServiceID("12345"),
wrapper.Meter(m),
)
_ = m.Init()
ctx := context.Background()
c := client.NewClient(client.Wrap(w))
c := client.NewClient()
if err := c.Init(); err != nil {
t.Fatal(err)
}
@ -34,7 +27,7 @@ func TestWrapper(t *testing.T) {
_, _ = rsp, err
buf := bytes.NewBuffer(nil)
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{micro_endpoint="svc2.Service.Method"} 0`)) {
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{endpoint="svc2.Service.Method"} 0`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes())
}
}

View File

@ -9,22 +9,15 @@ import (
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/meter"
"go.unistack.org/micro/v3/meter/wrapper"
)
func TestWrapper(t *testing.T) {
m := victoriametrics.NewMeter() // meter.Labels("test_key", "test_val"))
w := wrapper.NewClientWrapper(
wrapper.ServiceName("svc1"),
wrapper.ServiceVersion("0.0.1"),
wrapper.ServiceID("12345"),
wrapper.Meter(m),
)
_ = m.Init()
ctx := context.Background()
c := client.NewClient(client.Wrap(w))
c := client.NewClient()
if err := c.Init(); err != nil {
t.Fatal(err)
}
@ -34,7 +27,7 @@ func TestWrapper(t *testing.T) {
_, _ = rsp, err
buf := bytes.NewBuffer(nil)
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{micro_endpoint="svc2.Service.Method"} 0`)) {
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{endpoint="svc2.Service.Method"} 0`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes())
}
}

3
proto/generate.go Normal file
View File

@ -0,0 +1,3 @@
package pb
//go:generate ./generate.sh

9
proto/generate.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh -e
INC=$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3)
INC_CODEC=$(go list -f '{{ .Dir }}' -m go.unistack.org/micro/v3)
ARGS="-I${INC}"
CODEC_ARGS="-I${INC_CODEC}"
protoc $ARGS $CODEC_ARGS -I. --go_out=paths=source_relative:./ *.proto

340
proto/test.pb.go Normal file
View File

@ -0,0 +1,340 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v5.28.3
// source: test.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Item1 struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Key1 string `protobuf:"bytes,1,opt,name=key1,proto3" json:"key1,omitempty"`
}
func (x *Item1) Reset() {
*x = Item1{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Item1) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Item1) ProtoMessage() {}
func (x *Item1) ProtoReflect() protoreflect.Message {
mi := &file_test_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Item1.ProtoReflect.Descriptor instead.
func (*Item1) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{0}
}
func (x *Item1) GetKey1() string {
if x != nil {
return x.Key1
}
return ""
}
type Message1 struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Items []*Item1 `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
}
func (x *Message1) Reset() {
*x = Message1{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Message1) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Message1) ProtoMessage() {}
func (x *Message1) ProtoReflect() protoreflect.Message {
mi := &file_test_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Message1.ProtoReflect.Descriptor instead.
func (*Message1) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{1}
}
func (x *Message1) GetItems() []*Item1 {
if x != nil {
return x.Items
}
return nil
}
type Item2 struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Key1 string `protobuf:"bytes,1,opt,name=key1,proto3" json:"key1,omitempty"`
Key2 string `protobuf:"bytes,2,opt,name=key2,proto3" json:"key2,omitempty"`
}
func (x *Item2) Reset() {
*x = Item2{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Item2) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Item2) ProtoMessage() {}
func (x *Item2) ProtoReflect() protoreflect.Message {
mi := &file_test_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Item2.ProtoReflect.Descriptor instead.
func (*Item2) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{2}
}
func (x *Item2) GetKey1() string {
if x != nil {
return x.Key1
}
return ""
}
func (x *Item2) GetKey2() string {
if x != nil {
return x.Key2
}
return ""
}
type Message2 struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Items []*Item2 `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
}
func (x *Message2) Reset() {
*x = Message2{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Message2) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Message2) ProtoMessage() {}
func (x *Message2) ProtoReflect() protoreflect.Message {
mi := &file_test_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Message2.ProtoReflect.Descriptor instead.
func (*Message2) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{3}
}
func (x *Message2) GetItems() []*Item2 {
if x != nil {
return x.Items
}
return nil
}
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, 0x05, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0x1b, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x31, 0x12, 0x12, 0x0a, 0x04,
0x6b, 0x65, 0x79, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x31,
0x22, 0x2e, 0x0a, 0x08, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x31, 0x12, 0x22, 0x0a, 0x05,
0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x31, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73,
0x22, 0x2f, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x65, 0x79,
0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x31, 0x12, 0x12, 0x0a,
0x04, 0x6b, 0x65, 0x79, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x65, 0x79,
0x32, 0x22, 0x2e, 0x0a, 0x08, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x12, 0x22, 0x0a,
0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x32, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d,
0x73, 0x42, 0x0b, 0x5a, 0x09, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_test_proto_rawDescOnce sync.Once
file_test_proto_rawDescData = file_test_proto_rawDesc
)
func file_test_proto_rawDescGZIP() []byte {
file_test_proto_rawDescOnce.Do(func() {
file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData)
})
return file_test_proto_rawDescData
}
var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_test_proto_goTypes = []interface{}{
(*Item1)(nil), // 0: proto.Item1
(*Message1)(nil), // 1: proto.Message1
(*Item2)(nil), // 2: proto.Item2
(*Message2)(nil), // 3: proto.Message2
}
var file_test_proto_depIdxs = []int32{
0, // 0: proto.Message1.items:type_name -> proto.Item1
2, // 1: proto.Message2.items:type_name -> proto.Item2
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_test_proto_init() }
func file_test_proto_init() {
if File_test_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Item1); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Message1); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Item2); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Message2); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_test_proto_goTypes,
DependencyIndexes: file_test_proto_depIdxs,
MessageInfos: file_test_proto_msgTypes,
}.Build()
File_test_proto = out.File
file_test_proto_rawDesc = nil
file_test_proto_goTypes = nil
file_test_proto_depIdxs = nil
}

23
proto/test.proto Normal file
View File

@ -0,0 +1,23 @@
syntax = "proto3";
package proto;
option go_package="/proto;pb";
message Item1 {
string key1 = 1;
}
message Message1 {
repeated Item1 items = 1;
}
message Item2 {
string key1 = 1;
string key2 = 2;
}
message Message2 {
repeated Item2 items = 1;
}

26
proto/unmrashal_test.go Normal file
View File

@ -0,0 +1,26 @@
package pb
import (
"fmt"
"testing"
cp "go.unistack.org/micro-codec-proto/v3"
)
func TestMarshalUnmarshal(t *testing.T) {
c := cp.NewCodec()
msg2 := &Message2{Items: []*Item2{{Key1: "akey1", Key2: "akey2"}, {Key1: "bkey1", Key2: "bkey2"}}}
buf, err := c.Marshal(msg2)
if err != nil {
t.Fatal(err)
}
msg1 := &Message1{}
err = c.Unmarshal(buf, msg1)
if err != nil {
t.Fatal(err)
}
for _, item := range msg1.Items {
fmt.Printf("item %#+v\n", item)
}
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb
@ -603,24 +603,24 @@ var file_test_proto_rawDesc = []byte{
0x12, 0x9a, 0x01, 0x0a, 0x0d, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61,
0x72, 0x74, 0x12, 0x12, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70,
0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x75,
0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x52, 0x73, 0x70, 0x22, 0x61, 0xb2, 0xea, 0xff, 0xf9,
0x01, 0x15, 0x22, 0x10, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69,
0x70, 0x61, 0x72, 0x74, 0x3a, 0x01, 0x2a, 0xaa, 0x84, 0x9e, 0x03, 0x41, 0x2a, 0x0d, 0x54, 0x65,
0x73, 0x74, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x3a, 0x30, 0x0a, 0x2e, 0x12,
0x2c, 0x0a, 0x2a, 0x0a, 0x13, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x2f, 0x66,
0x6f, 0x72, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x12, 0x13, 0x0a, 0x11, 0x12, 0x0f, 0x0a, 0x0d,
0x2e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x12, 0xa2, 0x01,
0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x52, 0x73, 0x70, 0x22, 0x61, 0xaa, 0x84, 0x9e, 0x03,
0x41, 0x2a, 0x0d, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74,
0x3a, 0x30, 0x0a, 0x2e, 0x12, 0x2c, 0x0a, 0x2a, 0x0a, 0x13, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70,
0x61, 0x72, 0x74, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x12, 0x13, 0x0a,
0x11, 0x12, 0x0f, 0x0a, 0x0d, 0x2e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x52,
0x65, 0x71, 0xb2, 0xea, 0xff, 0xf9, 0x01, 0x15, 0x22, 0x10, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x73,
0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x3a, 0x01, 0x2a, 0x12, 0xa2, 0x01,
0x0a, 0x0c, 0x54, 0x65, 0x73, 0x74, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0d,
0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x73, 0xb2,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x73, 0xaa,
0x84, 0x9e, 0x03, 0x5b, 0x2a, 0x0c, 0x54, 0x65, 0x73, 0x74, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69,
0x6e, 0x74, 0x32, 0x25, 0x0a, 0x23, 0x0a, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x75,
0x69, 0x64, 0x12, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x01, 0x52, 0x0b, 0x0a, 0x09,
0xca, 0x01, 0x06, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x24, 0x0a, 0x22, 0x0a, 0x09, 0x63,
0x73, 0x72, 0x66, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x06, 0x63, 0x6f, 0x6f, 0x6b, 0x69, 0x65,
0x20, 0x01, 0x52, 0x0b, 0x0a, 0x09, 0xca, 0x01, 0x06, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xb2,
0xea, 0xff, 0xf9, 0x01, 0x0d, 0x12, 0x0b, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2f, 0x74, 0x65,
0x73, 0x74, 0xaa, 0x84, 0x9e, 0x03, 0x5b, 0x2a, 0x0c, 0x54, 0x65, 0x73, 0x74, 0x45, 0x6e, 0x64,
0x70, 0x6f, 0x69, 0x6e, 0x74, 0x32, 0x25, 0x0a, 0x23, 0x0a, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e,
0x74, 0x5f, 0x75, 0x69, 0x64, 0x12, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x01, 0x52,
0x0b, 0x0a, 0x09, 0xca, 0x01, 0x06, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x24, 0x0a, 0x22,
0x0a, 0x09, 0x63, 0x73, 0x72, 0x66, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x06, 0x63, 0x6f, 0x6f,
0x6b, 0x69, 0x65, 0x20, 0x01, 0x52, 0x0b, 0x0a, 0x09, 0xca, 0x01, 0x06, 0x73, 0x74, 0x72, 0x69,
0x6e, 0x67, 0x12, 0x3e, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x42, 0x79, 0x49, 0x44, 0x12, 0x0d,
0x73, 0x74, 0x12, 0x3e, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x42, 0x79, 0x49, 0x44, 0x12, 0x0d,
0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x13, 0xb2,
0xea, 0xff, 0xf9, 0x01, 0x0d, 0x12, 0x0b, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2f, 0x7b, 0x69,

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
@ -9,59 +9,12 @@ package pb
import (
context "context"
codec "go.unistack.org/micro-proto/v3/codec"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
TestServiceName = "TestService"
)
var (
TestServiceServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestService.TestMultipart",
Path: "/users/multipart",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "TestService.TestEndpoint",
Path: "/users/test",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UserByID",
Path: "/users/{id}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UserImageByID",
Path: "/users/{id}/image",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UploadFile",
Path: "/users/image/upload",
Method: "POST",
Body: "",
Stream: false,
},
{
Name: "TestService.KzAmlRs",
Path: "/aml",
Method: "POST",
Body: "",
Stream: false,
},
}
)
type TestServiceClient interface {
TestMultipart(ctx context.Context, req *MultipartReq, opts ...client.CallOption) (*MultipartRsp, error)

View File

@ -1,19 +1,66 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-client-http/v3"
v31 "go.unistack.org/micro-client-http/v3"
codec "go.unistack.org/micro-proto/v3/codec"
v31 "go.unistack.org/micro-server-http/v3"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
http "net/http"
)
var (
TestServiceServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestService.TestMultipart",
Path: "/users/multipart",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "TestService.TestEndpoint",
Path: "/users/test",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UserByID",
Path: "/users/{id}",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UserImageByID",
Path: "/users/{id}/image",
Method: "GET",
Body: "",
Stream: false,
},
{
Name: "TestService.UploadFile",
Path: "/users/image/upload",
Method: "POST",
Body: "",
Stream: false,
},
{
Name: "TestService.KzAmlRs",
Path: "/aml",
Method: "POST",
Body: "",
Stream: false,
},
}
)
type testServiceClient struct {
c client.Client
name string
@ -25,9 +72,9 @@ func NewTestServiceClient(name string, c client.Client) TestServiceClient {
func (c *testServiceClient) TestMultipart(ctx context.Context, req *MultipartReq, opts ...client.CallOption) (*MultipartRsp, error) {
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/users/multipart"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/users/multipart"),
v31.Body("*"),
)
rsp := &MultipartRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.TestMultipart", req), rsp, opts...)
@ -39,12 +86,12 @@ func (c *testServiceClient) TestMultipart(ctx context.Context, req *MultipartReq
func (c *testServiceClient) TestEndpoint(ctx context.Context, req *Request, opts ...client.CallOption) (*Response, error) {
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/users/test"),
v31.Method(http.MethodGet),
v31.Path("/users/test"),
)
opts = append(opts,
v3.Header("client_uid", "true"),
v3.Cookie("csrftoken", "true"),
v31.Header("client_uid", "true"),
v31.Cookie("csrftoken", "true"),
)
rsp := &Response{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.TestEndpoint", req), rsp, opts...)
@ -56,8 +103,8 @@ func (c *testServiceClient) TestEndpoint(ctx context.Context, req *Request, opts
func (c *testServiceClient) UserByID(ctx context.Context, req *Request, opts ...client.CallOption) (*Response, error) {
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/users/{id}"),
v31.Method(http.MethodGet),
v31.Path("/users/{id}"),
)
rsp := &Response{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.UserByID", req), rsp, opts...)
@ -69,8 +116,8 @@ func (c *testServiceClient) UserByID(ctx context.Context, req *Request, opts ...
func (c *testServiceClient) UserImageByID(ctx context.Context, req *Request, opts ...client.CallOption) (*codec.Frame, error) {
opts = append(opts,
v3.Method(http.MethodGet),
v3.Path("/users/{id}/image"),
v31.Method(http.MethodGet),
v31.Path("/users/{id}/image"),
)
rsp := &codec.Frame{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.UserImageByID", req), rsp, opts...)
@ -82,8 +129,8 @@ func (c *testServiceClient) UserImageByID(ctx context.Context, req *Request, opt
func (c *testServiceClient) UploadFile(ctx context.Context, req *RequestImage, opts ...client.CallOption) (*ResponseImage, error) {
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/users/image/upload"),
v31.Method(http.MethodPost),
v31.Path("/users/image/upload"),
)
rsp := &ResponseImage{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.UploadFile", req), rsp, opts...)
@ -95,8 +142,8 @@ func (c *testServiceClient) UploadFile(ctx context.Context, req *RequestImage, o
func (c *testServiceClient) KzAmlRs(ctx context.Context, req *RequestAml, opts ...client.CallOption) (*ResponseAml, error) {
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/aml"),
v31.Method(http.MethodPost),
v31.Path("/aml"),
)
rsp := &ResponseAml{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.KzAmlRs", req), rsp, opts...)
@ -115,9 +162,9 @@ func (h *testServiceServer) TestMultipart(ctx context.Context, req *MultipartReq
}
func (h *testServiceServer) TestEndpoint(ctx context.Context, req *Request, rsp *Response) error {
v31.FillRequest(ctx, req,
v31.Header("client_uid", "true"),
v31.Cookie("csrftoken", "true"),
v3.FillRequest(ctx, req,
v3.Header("client_uid", "true"),
v3.Cookie("csrftoken", "true"),
)
return h.TestServiceServer.TestEndpoint(ctx, req, rsp)
}
@ -152,6 +199,6 @@ func RegisterTestServiceServer(s server.Server, sh TestServiceServer, opts ...se
}
h := &testServiceServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(TestServiceServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(TestServiceServerEndpoints))
return s.Handle(s.NewHandler(&TestService{h}, append(nopts, opts...)...))
}

View File

@ -75,7 +75,7 @@ func TestComboServer(t *testing.T) {
h := &Handler{t: t}
_ = logger.DefaultLogger.Init(logger.WithCallerSkipCount(3))
_ = logger.DefaultLogger.Init()
// create grpc server
gsrv := grpcsrv.NewServer(

View File

@ -0,0 +1,17 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.4
package pb
import (
protojson "google.golang.org/protobuf/encoding/protojson"
)
var (
marshaler = protojson.MarshalOptions{}
)
func (m *Error) Error() string {
buf, _ := marshaler.Marshal(m)
return string(buf)
}

View File

@ -1,14 +1,13 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: proto.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/combo/proto"
client "go.unistack.org/micro/v3/client"
)
@ -16,17 +15,6 @@ import (
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.Call",
Path: "/Call",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestClient interface {
Call(ctx context.Context, req *proto.CallReq, opts ...client.CallOption) (*proto.CallRsp, error)

View File

@ -1,12 +1,11 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: proto.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/combo/proto"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
@ -17,7 +16,7 @@ type testClient struct {
name string
}
func NewTestClient(name string, c client.Client) TestClient {
func NewTestClient(name string, c client.Client) proto.TestClient {
return &testClient{c: c, name: name}
}
@ -31,14 +30,14 @@ func (c *testClient) Call(ctx context.Context, req *proto.CallReq, opts ...clien
}
type testServer struct {
TestServer
proto.TestServer
}
func (h *testServer) Call(ctx context.Context, req *proto.CallReq, rsp *proto.CallRsp) error {
return h.TestServer.Call(ctx, req, rsp)
}
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *proto.CallReq, rsp *proto.CallRsp) error
}
@ -47,6 +46,5 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp
}
h := &testServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
}

View File

@ -0,0 +1,17 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.4
package pb
import (
protojson "google.golang.org/protobuf/encoding/protojson"
)
var (
marshaler = protojson.MarshalOptions{}
)
func (m *Error) Error() string {
buf, _ := marshaler.Marshal(m)
return string(buf)
}

View File

@ -1,14 +1,13 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: proto.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/combo/proto"
client "go.unistack.org/micro/v3/client"
)
@ -16,17 +15,6 @@ import (
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.Call",
Path: "/Call",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestClient interface {
Call(ctx context.Context, req *proto.CallReq, opts ...client.CallOption) (*proto.CallRsp, error)

View File

@ -1,25 +1,37 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: proto.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-client-http/v3"
v31 "go.unistack.org/micro-server-http/v3"
v31 "go.unistack.org/micro-client-http/v3"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/combo/proto"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
http "net/http"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.Call",
Path: "/Call",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type testClient struct {
c client.Client
name string
}
func NewTestClient(name string, c client.Client) TestClient {
func NewTestClient(name string, c client.Client) proto.TestClient {
return &testClient{c: c, name: name}
}
@ -27,12 +39,12 @@ func (c *testClient) Call(ctx context.Context, req *proto.CallReq, opts ...clien
errmap := make(map[string]interface{}, 1)
errmap["default"] = &proto.Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/Call"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/Call"),
v31.Body("*"),
)
rsp := &proto.CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
@ -43,14 +55,14 @@ func (c *testClient) Call(ctx context.Context, req *proto.CallReq, opts ...clien
}
type testServer struct {
TestServer
proto.TestServer
}
func (h *testServer) Call(ctx context.Context, req *proto.CallReq, rsp *proto.CallRsp) error {
return h.TestServer.Call(ctx, req, rsp)
}
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *proto.CallReq, rsp *proto.CallRsp) error
}
@ -59,6 +71,6 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp
}
h := &testServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(TestServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: ngpb.proto
package pb

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v3.21.12
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.3
// source: ngpb.proto
package pb
@ -15,8 +15,8 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Test_Call_FullMethodName = "/test.v1.ngpb.Test/Call"
@ -39,8 +39,9 @@ func NewTestClient(cc grpc.ClientConnInterface) TestClient {
}
func (c *testClient) Call(ctx context.Context, in *CallReq, opts ...grpc.CallOption) (*CallRsp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CallRsp)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@ -49,21 +50,25 @@ func (c *testClient) Call(ctx context.Context, in *CallReq, opts ...grpc.CallOpt
// TestServer is the server API for Test service.
// All implementations must embed UnimplementedTestServer
// for forward compatibility
// for forward compatibility.
type TestServer interface {
// option (micro.api.micro_service) = { client_wrappers: ["one","two"]; };
Call(context.Context, *CallReq) (*CallRsp, error)
mustEmbedUnimplementedTestServer()
}
// UnimplementedTestServer must be embedded to have forward compatible implementations.
type UnimplementedTestServer struct {
}
// UnimplementedTestServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTestServer struct{}
func (UnimplementedTestServer) Call(context.Context, *CallReq) (*CallRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (UnimplementedTestServer) mustEmbedUnimplementedTestServer() {}
func (UnimplementedTestServer) testEmbeddedByValue() {}
// UnsafeTestServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TestServer will
@ -73,6 +78,13 @@ type UnsafeTestServer interface {
}
func RegisterTestServer(s grpc.ServiceRegistrar, srv TestServer) {
// If the following call pancis, it indicates UnimplementedTestServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Test_ServiceDesc, srv)
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: proto.proto
package pb

View File

@ -1,37 +1,47 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package helloworld
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/grpc/proto"
client "go.unistack.org/micro/v3/client"
metadata "go.unistack.org/micro/v3/metadata"
)
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.Call",
Path: "/api/v0/test/call/TEST",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestClient interface {
Call(ctx context.Context, req *proto.Request, opts ...client.CallOption) (*proto.Response, error)
StreamCall(ctx context.Context, opts ...client.CallOption) (Test_StreamCallClient, error)
}
type Test_StreamCallClient interface {
Context() context.Context
SendMsg(msg interface{}) error
RecvMsg(msg interface{}) error
Close() error
Header() metadata.Metadata
Send(msg *proto.Request) error
Recv() (*proto.Response, error)
}
type TestServer interface {
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
StreamCall(ctx context.Context, stream Test_StreamCallStream) error
}
type Test_StreamCallStream interface {
Context() context.Context
SendMsg(msg interface{}) error
RecvMsg(msg interface{}) error
Close() error
Recv() (*proto.Request, error)
Send(msg *proto.Response) error
}

View File

@ -1,14 +1,14 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package helloworld
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
proto "go.unistack.org/micro-tests/server/grpc/proto"
client "go.unistack.org/micro/v3/client"
metadata "go.unistack.org/micro/v3/metadata"
server "go.unistack.org/micro/v3/server"
)
@ -17,7 +17,7 @@ type testClient struct {
name string
}
func NewTestClient(name string, c client.Client) TestClient {
func NewTestClient(name string, c client.Client) proto.TestClient {
return &testClient{c: c, name: name}
}
@ -30,23 +30,107 @@ func (c *testClient) Call(ctx context.Context, req *proto.Request, opts ...clien
return rsp, nil
}
func (c *testClient) StreamCall(ctx context.Context, opts ...client.CallOption) (Test_StreamCallClient, error) {
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.StreamCall", &proto.Request{}), opts...)
if err != nil {
return nil, err
}
return &testClientStreamCall{stream}, nil
}
type testClientStreamCall struct {
stream client.Stream
}
func (s *testClientStreamCall) Close() error {
return s.stream.Close()
}
func (s *testClientStreamCall) CloseSend() error {
return s.stream.CloseSend()
}
func (s *testClientStreamCall) Context() context.Context {
return s.stream.Context()
}
func (s *testClientStreamCall) SendMsg(msg interface{}) error {
return s.stream.Send(msg)
}
func (s *testClientStreamCall) RecvMsg(msg interface{}) error {
return s.stream.Recv(msg)
}
func (s *testClientStreamCall) Header() metadata.Metadata {
return s.stream.Response().Header()
}
func (s *testClientStreamCall) Send(msg *proto.Request) error {
return s.stream.Send(msg)
}
func (s *testClientStreamCall) Recv() (*proto.Response, error) {
msg := &proto.Response{}
if err := s.stream.Recv(msg); err != nil {
return nil, err
}
return msg, nil
}
type testServer struct {
TestServer
proto.TestServer
}
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
return h.TestServer.Call(ctx, req, rsp)
}
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
func (h *testServer) StreamCall(ctx context.Context, stream server.Stream) error {
return h.TestServer.StreamCall(ctx, &testStreamCallStream{stream})
}
type testStreamCallStream struct {
stream server.Stream
}
func (s *testStreamCallStream) Close() error {
return s.stream.Close()
}
func (s *testStreamCallStream) Context() context.Context {
return s.stream.Context()
}
func (s *testStreamCallStream) SendMsg(msg interface{}) error {
return s.stream.Send(msg)
}
func (s *testStreamCallStream) RecvMsg(msg interface{}) error {
return s.stream.Recv(msg)
}
func (s *testStreamCallStream) Send(msg *proto.Response) error {
return s.stream.Send(msg)
}
func (s *testStreamCallStream) Recv() (*proto.Request, error) {
msg := &proto.Request{}
if err := s.stream.Recv(msg); err != nil {
return nil, err
}
return msg, nil
}
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
StreamCall(ctx context.Context, stream server.Stream) error
}
type Test struct {
test
}
h := &testServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package helloworld
@ -204,13 +204,17 @@ var file_test_proto_rawDesc = []byte{
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, 0xb2, 0xea, 0xff, 0xf9, 0x01, 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, 0x3a, 0x5a, 0x38, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69,
0x52, 0x06, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0x9b, 0x01, 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, 0xb2, 0xea, 0xff, 0xf9, 0x01, 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, 0x12, 0x3d, 0x0a, 0x0a, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 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, 0x28, 0x01, 0x30, 0x01, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69,
0x73, 0x74, 0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d,
0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x67, 0x72, 0x70,
0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72,
@ -239,9 +243,11 @@ var file_test_proto_depIdxs = []int32{
1, // 0: helloworld.Request.broken:type_name -> helloworld.Broken
1, // 1: helloworld.Response.broken:type_name -> helloworld.Broken
0, // 2: helloworld.Test.Call:input_type -> helloworld.Request
2, // 3: helloworld.Test.Call:output_type -> helloworld.Response
3, // [3:4] is the sub-list for method output_type
2, // [2:3] is the sub-list for method input_type
0, // 3: helloworld.Test.StreamCall:input_type -> helloworld.Request
2, // 4: helloworld.Test.Call:output_type -> helloworld.Response
2, // 5: helloworld.Test.StreamCall:output_type -> helloworld.Response
4, // [4:6] is the sub-list for method output_type
2, // [2:4] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name

View File

@ -13,6 +13,7 @@ service Test {
body: "*";
};
}
rpc StreamCall(stream Request) returns (stream Response) {};
}
message Request {

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v3.21.12
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.3
// source: test.proto
package helloworld
@ -15,11 +15,12 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Test_Call_FullMethodName = "/helloworld.Test/Call"
Test_StreamCall_FullMethodName = "/helloworld.Test/StreamCall"
)
// TestClient is the client API for Test service.
@ -27,6 +28,7 @@ const (
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type TestClient interface {
Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
StreamCall(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error)
}
type testClient struct {
@ -38,30 +40,52 @@ func NewTestClient(cc grpc.ClientConnInterface) TestClient {
}
func (c *testClient) Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Test_Call_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testClient) StreamCall(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &Test_ServiceDesc.Streams[0], Test_StreamCall_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[Request, Response]{ClientStream: stream}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type Test_StreamCallClient = grpc.BidiStreamingClient[Request, Response]
// TestServer is the server API for Test service.
// All implementations must embed UnimplementedTestServer
// for forward compatibility
// for forward compatibility.
type TestServer interface {
Call(context.Context, *Request) (*Response, error)
StreamCall(grpc.BidiStreamingServer[Request, Response]) error
mustEmbedUnimplementedTestServer()
}
// UnimplementedTestServer must be embedded to have forward compatible implementations.
type UnimplementedTestServer struct {
}
// UnimplementedTestServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTestServer struct{}
func (UnimplementedTestServer) Call(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (UnimplementedTestServer) StreamCall(grpc.BidiStreamingServer[Request, Response]) error {
return status.Errorf(codes.Unimplemented, "method StreamCall not implemented")
}
func (UnimplementedTestServer) mustEmbedUnimplementedTestServer() {}
func (UnimplementedTestServer) testEmbeddedByValue() {}
// UnsafeTestServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TestServer will
@ -71,6 +95,13 @@ type UnsafeTestServer interface {
}
func RegisterTestServer(s grpc.ServiceRegistrar, srv TestServer) {
// If the following call pancis, it indicates UnimplementedTestServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Test_ServiceDesc, srv)
}
@ -92,6 +123,13 @@ func _Test_Call_Handler(srv interface{}, ctx context.Context, dec func(interface
return interceptor(ctx, in, info, handler)
}
func _Test_StreamCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServer).StreamCall(&grpc.GenericServerStream[Request, Response]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type Test_StreamCallServer = grpc.BidiStreamingServer[Request, Response]
// Test_ServiceDesc is the grpc.ServiceDesc for Test service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -104,6 +142,13 @@ var Test_ServiceDesc = grpc.ServiceDesc{
Handler: _Test_Call_Handler,
},
},
Streams: []grpc.StreamDesc{},
Streams: []grpc.StreamDesc{
{
StreamName: "StreamCall",
Handler: _Test_StreamCall_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "test.proto",
}

View File

@ -0,0 +1,17 @@
package http_handler
import (
"net/http"
"testing"
swaggerui "go.unistack.org/micro-server-http/v3/handler/swagger-ui"
)
func TestTemplate(t *testing.T) {
// t.Skip()
h := http.NewServeMux()
h.HandleFunc("/", swaggerui.Handler(""))
if err := http.ListenAndServe(":8080", h); err != nil {
t.Fatal(err)
}
}

View File

@ -24,10 +24,7 @@ import (
meterhandler "go.unistack.org/micro-server-http/v3/handler/meter"
pb "go.unistack.org/micro-tests/server/http/proto"
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/logger"
lwrapper "go.unistack.org/micro/v3/logger/wrapper"
"go.unistack.org/micro/v3/metadata"
mwrapper "go.unistack.org/micro/v3/meter/wrapper"
"go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v3/server"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
@ -363,8 +360,6 @@ func TestNativeClientServer(t *testing.T) {
server.Register(reg),
server.Codec("application/json", jsonpbcodec.NewCodec()),
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
server.WrapHandler(mwrapper.NewHandlerWrapper(mwrapper.Meter(m))),
server.WrapHandler(lwrapper.NewServerHandlerWrapper(lwrapper.WithEnabled(false), lwrapper.WithLevel(logger.ErrorLevel))),
httpsrv.Middleware(mwf),
server.WrapHandler(NewServerHandlerWrapper(t)),
)

View File

@ -0,0 +1,17 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.4
package pb
import (
protojson "google.golang.org/protobuf/encoding/protojson"
)
var (
marshaler = protojson.MarshalOptions{}
)
func (m *Error) Error() string {
buf, _ := marshaler.Marshal(m)
return string(buf)
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb

View File

@ -1,31 +1,19 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// - protoc-gen-go-micro v3.10.4
// - protoc v5.28.3
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
TestDoubleName = "TestDouble"
)
var (
TestDoubleServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestDouble.CallDouble",
Path: "/v1/testdouble/call/name/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestDoubleClient interface {
CallDouble(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
@ -38,38 +26,6 @@ type TestDoubleServer interface {
var (
TestName = "Test"
)
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.CallRepeatedString",
Path: "/v1/test/call_repeated_string",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.CallRepeatedInt64",
Path: "/v1/test/call_repeated_int64",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.Call",
Path: "/v1/test/call/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.CallError",
Path: "/v1/test/callerror/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type TestClient interface {
CallRepeatedString(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)

View File

@ -1,19 +1,31 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.10.2
// protoc-gen-go-micro version: v3.10.4
// source: test.proto
package pb
import (
context "context"
v3 "go.unistack.org/micro-client-http/v3"
v31 "go.unistack.org/micro-server-http/v3"
v31 "go.unistack.org/micro-client-http/v3"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
http "net/http"
time "time"
)
var (
TestDoubleServerEndpoints = []v3.EndpointMetadata{
{
Name: "TestDouble.CallDouble",
Path: "/v1/testdouble/call/name/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type testDoubleClient struct {
c client.Client
name string
@ -27,12 +39,12 @@ func (c *testDoubleClient) CallDouble(ctx context.Context, req *CallReq, opts ..
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/testdouble/call/name/{name}"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/testdouble/call/name/{name}"),
v31.Body("*"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -65,10 +77,43 @@ func RegisterTestDoubleServer(s server.Server, sh TestDoubleServer, opts ...serv
}
h := &testDoubleServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(TestDoubleServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(TestDoubleServerEndpoints))
return s.Handle(s.NewHandler(&TestDouble{h}, append(nopts, opts...)...))
}
var (
TestServerEndpoints = []v3.EndpointMetadata{
{
Name: "Test.CallRepeatedString",
Path: "/v1/test/call_repeated_string",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.CallRepeatedInt64",
Path: "/v1/test/call_repeated_int64",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.Call",
Path: "/v1/test/call/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
{
Name: "Test.CallError",
Path: "/v1/test/callerror/{name}",
Method: "POST",
Body: "*",
Stream: false,
},
}
)
type testClient struct {
c client.Client
name string
@ -82,12 +127,12 @@ func (c *testClient) CallRepeatedString(ctx context.Context, req *CallReq, opts
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/test/call_repeated_string"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/test/call_repeated_string"),
v31.Body("*"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -103,12 +148,12 @@ func (c *testClient) CallRepeatedInt64(ctx context.Context, req *CallReq, opts .
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/test/call_repeated_int64"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/test/call_repeated_int64"),
v31.Body("*"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -124,16 +169,16 @@ func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.Call
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/test/call/{name}"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/test/call/{name}"),
v31.Body("*"),
)
opts = append(opts,
v3.Header("Clientid", "true"),
v3.Cookie("Csrftoken", "true"),
v31.Header("Clientid", "true"),
v31.Cookie("Csrftoken", "true"),
)
td := time.Duration(5000000000)
opts = append(opts, client.WithRequestTimeout(td))
@ -149,12 +194,12 @@ func (c *testClient) CallError(ctx context.Context, req *CallReq1, opts ...clien
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v31.ErrorMap(errmap),
)
opts = append(opts,
v3.Method(http.MethodPost),
v3.Path("/v1/test/callerror/{name}"),
v3.Body("*"),
v31.Method(http.MethodPost),
v31.Path("/v1/test/callerror/{name}"),
v31.Body("*"),
)
rsp := &CallRsp1{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.CallError", req), rsp, opts...)
@ -189,9 +234,9 @@ func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
td := time.Duration(5000000000)
ctx, cancel = context.WithTimeout(ctx, td)
defer cancel()
v31.FillRequest(ctx, req,
v31.Header("Clientid", "true"),
v31.Cookie("Csrftoken", "true"),
v3.FillRequest(ctx, req,
v3.Header("Clientid", "true"),
v3.Cookie("Csrftoken", "true"),
)
return h.TestServer.Call(ctx, req, rsp)
}
@ -212,6 +257,6 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp
}
h := &testServer{sh}
var nopts []server.HandlerOption
nopts = append(nopts, v31.HandlerEndpoints(TestServerEndpoints))
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
}

Binary file not shown.

View File

@ -0,0 +1,117 @@
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
sgrpc "go.unistack.org/micro-server-grpc/v3"
"go.unistack.org/micro/v3"
"go.unistack.org/micro/v3/server"
grpc "google.golang.org/grpc"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
func main() {
switch os.Args[1] {
case "server":
TestServer()
case "client":
TestClient()
}
}
type serv struct {
UnimplementedTestServiceServer
}
func (s *serv) DoWork(ctx context.Context, in *emptypb.Empty) (*WorkResponse, error) {
fmt.Println("Starting long-running operation")
time.Sleep(4 * time.Second)
select {
case <-ctx.Done():
fmt.Println("Operation interrupted")
return nil, ctx.Err()
default:
fmt.Println("Operation completed")
return &WorkResponse{Message: "Work done"}, nil
}
}
func startServer(ctx context.Context) {
s := sgrpc.NewServer(server.Name("Service"), server.Address("localhost:1234"))
svc := micro.NewService(
micro.Context(ctx),
micro.Server(s),
)
svc.Init()
RegisterTestServiceServer(s.GRPCServer(), &serv{})
go func() {
fmt.Printf("wait for ctx.Done\n")
<-ctx.Done()
fmt.Printf("wait for Stop\n")
svc.Stop(ctx)
fmt.Printf("Stopped\n")
}()
fmt.Printf("svc Run\n")
svc.Run()
fmt.Printf("svc End\n")
}
func TestClient() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Printf("create grpc conn\n")
conn, _ := grpc.Dial("localhost:1234", grpc.WithInsecure(), grpc.WithBlock())
defer conn.Close()
cli := NewTestServiceClient(conn)
replyCh := make(chan string)
go func() {
resp, err := cli.DoWork(ctx, &emptypb.Empty{})
if err != nil {
fmt.Println("Client call failed:", err)
replyCh <- ""
} else {
replyCh <- resp.Message
}
}()
p, _ := os.FindProcess(os.Getpid())
_ = p
//_ = p.Signal(syscall.SIGTERM)
select {
case reply := <-replyCh:
if reply != "Work done" {
log.Printf("Expected reply 'Work done', got '%s'\n", reply)
} else {
log.Printf("all fine\n")
}
case <-ctx.Done():
log.Printf("Request was not completed\n")
}
}
func TestServer() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
sigReceived := <-sig
fmt.Printf("handle signal %v, exiting\n", sigReceived)
cancel()
}()
log.Printf("run server\n")
startServer(ctx)
}

View File

@ -0,0 +1,154 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc v5.28.2
// source: testservice.proto
package main
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type WorkResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *WorkResponse) Reset() {
*x = WorkResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_testservice_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *WorkResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*WorkResponse) ProtoMessage() {}
func (x *WorkResponse) ProtoReflect() protoreflect.Message {
mi := &file_testservice_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use WorkResponse.ProtoReflect.Descriptor instead.
func (*WorkResponse) Descriptor() ([]byte, []int) {
return file_testservice_proto_rawDescGZIP(), []int{0}
}
func (x *WorkResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_testservice_proto protoreflect.FileDescriptor
var file_testservice_proto_rawDesc = []byte{
0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x12, 0x07, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x1a, 0x1b, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d,
0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x28, 0x0a, 0x0c, 0x57, 0x6f, 0x72,
0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x32, 0x46, 0x0a, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x6f, 0x57, 0x6f, 0x72, 0x6b, 0x12, 0x16, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45,
0x6d, 0x70, 0x74, 0x79, 0x1a, 0x15, 0x2e, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x2e, 0x57,
0x6f, 0x72, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x24, 0x5a, 0x22, 0x70,
0x61, 0x74, 0x68, 0x2f, 0x74, 0x6f, 0x2f, 0x79, 0x6f, 0x75, 0x72, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
0x65, 0x2f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3b, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65,
0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_testservice_proto_rawDescOnce sync.Once
file_testservice_proto_rawDescData = file_testservice_proto_rawDesc
)
func file_testservice_proto_rawDescGZIP() []byte {
file_testservice_proto_rawDescOnce.Do(func() {
file_testservice_proto_rawDescData = protoimpl.X.CompressGZIP(file_testservice_proto_rawDescData)
})
return file_testservice_proto_rawDescData
}
var file_testservice_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_testservice_proto_goTypes = []interface{}{
(*WorkResponse)(nil), // 0: handler.WorkResponse
(*emptypb.Empty)(nil), // 1: google.protobuf.Empty
}
var file_testservice_proto_depIdxs = []int32{
1, // 0: handler.TestService.DoWork:input_type -> google.protobuf.Empty
0, // 1: handler.TestService.DoWork:output_type -> handler.WorkResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_testservice_proto_init() }
func file_testservice_proto_init() {
if File_testservice_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_testservice_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*WorkResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_testservice_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_testservice_proto_goTypes,
DependencyIndexes: file_testservice_proto_depIdxs,
MessageInfos: file_testservice_proto_msgTypes,
}.Build()
File_testservice_proto = out.File
file_testservice_proto_rawDesc = nil
file_testservice_proto_goTypes = nil
file_testservice_proto_depIdxs = nil
}

View File

@ -0,0 +1,13 @@
syntax = "proto3";
package main;
import "google/protobuf/empty.proto";
service TestService {
rpc DoWork (google.protobuf.Empty) returns (WorkResponse);
}
message WorkResponse {
string message = 1;
}

View File

@ -0,0 +1,122 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.2
// source: testservice.proto
package main
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
TestService_DoWork_FullMethodName = "/handler.TestService/DoWork"
)
// TestServiceClient is the client API for TestService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type TestServiceClient interface {
DoWork(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*WorkResponse, error)
}
type testServiceClient struct {
cc grpc.ClientConnInterface
}
func NewTestServiceClient(cc grpc.ClientConnInterface) TestServiceClient {
return &testServiceClient{cc}
}
func (c *testServiceClient) DoWork(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*WorkResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(WorkResponse)
err := c.cc.Invoke(ctx, TestService_DoWork_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// TestServiceServer is the server API for TestService service.
// All implementations must embed UnimplementedTestServiceServer
// for forward compatibility.
type TestServiceServer interface {
DoWork(context.Context, *emptypb.Empty) (*WorkResponse, error)
mustEmbedUnimplementedTestServiceServer()
}
// UnimplementedTestServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTestServiceServer struct{}
func (UnimplementedTestServiceServer) DoWork(context.Context, *emptypb.Empty) (*WorkResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DoWork not implemented")
}
func (UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {}
func (UnimplementedTestServiceServer) testEmbeddedByValue() {}
// UnsafeTestServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TestServiceServer will
// result in compilation errors.
type UnsafeTestServiceServer interface {
mustEmbedUnimplementedTestServiceServer()
}
func RegisterTestServiceServer(s grpc.ServiceRegistrar, srv TestServiceServer) {
// If the following call pancis, it indicates UnimplementedTestServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&TestService_ServiceDesc, srv)
}
func _TestService_DoWork_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(emptypb.Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TestServiceServer).DoWork(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: TestService_DoWork_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServiceServer).DoWork(ctx, req.(*emptypb.Empty))
}
return interceptor(ctx, in, info, handler)
}
// TestService_ServiceDesc is the grpc.ServiceDesc for TestService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var TestService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "handler.TestService",
HandlerType: (*TestServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "DoWork",
Handler: _TestService_DoWork_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "testservice.proto",
}

View File

@ -24,7 +24,6 @@ import (
"go.unistack.org/micro/v3/router"
"go.unistack.org/micro/v3/server"
mt "go.unistack.org/micro/v3/tracer"
otwrapper "go.unistack.org/micro/v3/tracer/wrapper"
)
type Test interface {
@ -124,7 +123,6 @@ func TestClient(t *testing.T) {
client.Codec("application/grpc+json", jsoncodec.NewCodec()),
client.Codec("application/json", jsoncodec.NewCodec()),
client.Router(rt),
client.Wrap(otwrapper.NewClientWrapper(otwrapper.WithTracer(mtr))),
)
if err := c.Init(); err != nil {
@ -139,8 +137,7 @@ func TestClient(t *testing.T) {
server.ID(serverID),
server.Register(reg),
server.Broker(brk),
server.WrapSubscriber(otwrapper.NewServerSubscriberWrapper(otwrapper.WithTracer(mtr))),
server.WrapHandler(otwrapper.NewServerHandlerWrapper(otwrapper.WithTracer(mtr))),
server.Tracer(mtr),
server.Address("127.0.0.1:0"),
)
if err := s.Init(); err != nil {

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.12
// protoc v5.28.3
// source: test.proto
package pb