add reflection so that you can use it to get definition of services

This commit is contained in:
smallnest
2020-01-22 16:29:14 +08:00
parent 4f758db059
commit dc4b1b103d
4 changed files with 242 additions and 17 deletions

View File

@@ -0,0 +1,28 @@
package reflection
import (
"context"
"testing"
"github.com/kr/pretty"
testutils "github.com/smallnest/rpcx/_testutils"
)
type PBArith int
func (t *PBArith) Mul(ctx context.Context, args *testutils.ProtoArgs, reply *testutils.ProtoReply) error {
reply.C = args.A * args.B
return nil
}
func TestReflection_Register(t *testing.T) {
r := New()
arith := PBArith(0)
err := r.Register("Arith", &arith, "")
if err != nil {
t.Fatal(err)
}
pretty.Println(r.Services["PBArith"].String())
}