1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

feat: add test framework & refactor RPC server (#2579)

Co-authored-by: Rene Jochum <rene@jochum.dev>
This commit is contained in:
David Brouwer
2022-10-20 13:00:50 +02:00
committed by GitHub
parent c25dee7c8a
commit a3980c2308
54 changed files with 3703 additions and 2497 deletions

View File

@ -3,6 +3,8 @@ package handler
import (
"context"
"errors"
"io"
"time"
"go-micro.dev/v4/client"
@ -10,7 +12,6 @@ import (
proto "go-micro.dev/v4/debug/proto"
"go-micro.dev/v4/debug/stats"
"go-micro.dev/v4/debug/trace"
"go-micro.dev/v4/server"
)
// NewHandler returns an instance of the Debug Handler.
@ -22,6 +23,8 @@ func NewHandler(c client.Client) *Debug {
}
}
var _ proto.DebugHandler = (*Debug)(nil)
type Debug struct {
// must honor the debug handler
proto.DebugHandler
@ -38,6 +41,25 @@ func (d *Debug) Health(ctx context.Context, req *proto.HealthRequest, rsp *proto
return nil
}
func (d *Debug) MessageBus(ctx context.Context, stream proto.Debug_MessageBusStream) error {
for {
_, err := stream.Recv()
if errors.Is(err, io.EOF) {
return nil
} else if err != nil {
return err
}
rsp := proto.BusMsg{
Msg: "Request received!",
}
if err := stream.Send(&rsp); err != nil {
return err
}
}
}
func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.StatsResponse) error {
stats, err := d.stats.Read()
if err != nil {
@ -92,11 +114,7 @@ func (d *Debug) Trace(ctx context.Context, req *proto.TraceRequest, rsp *proto.T
return nil
}
func (d *Debug) Log(ctx context.Context, stream server.Stream) error {
req := new(proto.LogRequest)
if err := stream.Recv(req); err != nil {
return err
}
func (d *Debug) Log(ctx context.Context, req *proto.LogRequest, stream proto.Debug_LogStream) error {
var options []log.ReadOption