Skip to content

Commit

Permalink
chore: unexport symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed May 24, 2023
1 parent 8781ea8 commit 88b92ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
18 changes: 9 additions & 9 deletions pkg/generic/reflect_test/map_test.go
Expand Up @@ -49,19 +49,19 @@ func BenchmarkThriftMapExample(b *testing.B) {
func testThriftMapExample(t testing.TB) {
log_id := strconv.Itoa(rand.Int())

req := MakeExampleReqMap(true, ReqMsg, log_id)
req := makeExampleReqMap(true, reqMsg, log_id)

out, err := mcli.GenericCall(context.Background(), Method, req, callopt.WithRPCTimeout(100*time.Second))
out, err := mcli.GenericCall(context.Background(), method, req, callopt.WithRPCTimeout(100*time.Second))
test.Assert(t, err == nil, err)
resp, ok := out.(map[string]interface{})
test.Assert(t, ok)

msg, ok := resp["Msg"].(string)
if !ok || msg != RespMsg {
if !ok || msg != respMsg {
t.Fail()
}
require_field, ok := resp["required_field"].(string)
if !ok || require_field != ReqMsg {
if !ok || require_field != reqMsg {
t.Fail()
}
logid, ok := resp["BaseResp"].(map[string]interface{})["StatusMessage"]
Expand Down Expand Up @@ -124,10 +124,10 @@ func newGenericServer(g generic.Generic, addr net.Addr, handler generic.Service)
return svr
}

type ExampeServerImpl struct{}
type exampeServerImpl struct{}

// GenericCall ...
func (g *ExampeServerImpl) GenericCall(ctx context.Context, method string, request interface{}) (response interface{}, err error) {
func (g *exampeServerImpl) GenericCall(ctx context.Context, method string, request interface{}) (response interface{}, err error) {
buf := request.(map[string]interface{})

required_field := ""
Expand All @@ -147,10 +147,10 @@ func (g *ExampeServerImpl) GenericCall(ctx context.Context, method string, reque
}
}

return MakeExampleRespMap(RespMsg, required_field, logid)
return makeExampleRespMap(respMsg, required_field, logid)
}

func MakeExampleRespMap(msg, require_field, logid string) (map[string]interface{}, error) {
func makeExampleRespMap(msg, require_field, logid string) (map[string]interface{}, error) {
return map[string]interface{}{
"Msg": msg,
"required_field": require_field,
Expand All @@ -160,7 +160,7 @@ func MakeExampleRespMap(msg, require_field, logid string) (map[string]interface{
}, nil
}

func MakeExampleReqMap(B bool, A, logid string) map[string]interface{} {
func makeExampleReqMap(B bool, A, logid string) map[string]interface{} {
list := make([]interface{}, SampleListSize+1)
list[0] = map[string]interface{}{
"Bar": A,
Expand Down
72 changes: 36 additions & 36 deletions pkg/generic/reflect_test/reflect_test.go
@@ -1,5 +1,5 @@
/*
* Copyright 2021 CloudWeGo Authors
* Copyright 2023 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestMain(m *testing.M) {
svr := initServer(":9090")
cli = initClient("127.0.0.1:9090")

msvr := initThriftMapServer(":9101", "./idl/example.thrift", new(ExampeServerImpl))
msvr := initThriftMapServer(":9101", "./idl/example.thrift", new(exampeServerImpl))
mcli = initThriftMapClient("127.0.0.1:9101", "./idl/example.thrift")

ret := m.Run()
Expand Down Expand Up @@ -83,19 +83,19 @@ func testThriftReflectExample_Node(t testing.TB) {
log_id := strconv.Itoa(rand.Int())

// make a request body
req, err := MakeExampleReqBinary(true, ReqMsg, log_id)
req, err := makeExampleReqBinary(true, reqMsg, log_id)
if err != nil {
t.Fatal(err)
}

// wrap request as thrift CALL message
buf, err := dt.WrapBinaryBody(req, Method, dt.CALL, 1, 0)
buf, err := dt.WrapBinaryBody(req, method, dt.CALL, 1, 0)
if err != nil {
t.Fatal(err)
}

// generic call
out, err := cli.GenericCall(context.Background(), Method, buf, callopt.WithRPCTimeout(1*time.Second))
out, err := cli.GenericCall(context.Background(), method, buf, callopt.WithRPCTimeout(1*time.Second))
if err != nil {
t.Fatal(err)
}
Expand All @@ -119,19 +119,19 @@ func testThriftReflectExample_DOM(t testing.TB) {
log_id := strconv.Itoa(rand.Int())

// make a request body
req, err := MakeExampleReqBinary(true, ReqMsg, log_id)
req, err := makeExampleReqBinary(true, reqMsg, log_id)
if err != nil {
t.Fatal(err)
}

// wrap request as thrift CALL message
buf, err := dt.WrapBinaryBody(req, Method, dt.CALL, 1, 0)
buf, err := dt.WrapBinaryBody(req, method, dt.CALL, 1, 0)
if err != nil {
t.Fatal(err)
}

// generic call
out, err := cli.GenericCall(context.Background(), Method, buf, callopt.WithRPCTimeout(1*time.Second))
out, err := cli.GenericCall(context.Background(), method, buf, callopt.WithRPCTimeout(1*time.Second))
if err != nil {
t.Fatal(err)
}
Expand All @@ -150,22 +150,22 @@ func testThriftReflectExample_DOM(t testing.TB) {
}

var (
ExampleReqDesc *dt.TypeDescriptor
ExampleRespDesc *dt.TypeDescriptor
StrDesc *dt.TypeDescriptor
BaseLogidPath []dg.Path
DynamicgoOptions = &dg.Options{}
exampleReqDesc *dt.TypeDescriptor
exampleRespDesc *dt.TypeDescriptor
strDesc *dt.TypeDescriptor
baseLogidPath []dg.Path
dynamicgoOptions = &dg.Options{}
)

func initExampleDescriptor() {
sdesc, err := dt.NewDescritorFromPath(context.Background(), "idl/example.thrift")
if err != nil {
panic(err)
}
ExampleReqDesc = sdesc.Functions()["ExampleMethod"].Request().Struct().FieldById(1).Type()
ExampleRespDesc = sdesc.Functions()["ExampleMethod"].Response().Struct().FieldById(0).Type()
StrDesc = ExampleReqDesc.Struct().FieldById(1).Type()
BaseLogidPath = []dg.Path{dg.NewPathFieldName("Base"), dg.NewPathFieldName("LogID")}
exampleReqDesc = sdesc.Functions()["ExampleMethod"].Request().Struct().FieldById(1).Type()
exampleRespDesc = sdesc.Functions()["ExampleMethod"].Response().Struct().FieldById(0).Type()
strDesc = exampleReqDesc.Struct().FieldById(1).Type()
baseLogidPath = []dg.Path{dg.NewPathFieldName("Base"), dg.NewPathFieldName("LogID")}
}

func initServer(addr string) server.Server {
Expand All @@ -191,9 +191,9 @@ func initClient(addr string) genericclient.Client {
return genericCli
}

// MakeExampleRespBinary make a Thrift-Binary-Encoding response using ExampleResp DOM
// makeExampleRespBinary make a Thrift-Binary-Encoding response using ExampleResp DOM
// Except msg, require_field and logid, which are reset everytime
func MakeExampleRespBinary(msg, require_field, logid string) ([]byte, error) {
func makeExampleRespBinary(msg, require_field, logid string) ([]byte, error) {
dom := &dg.PathNode{
Node: dg.NewTypedNode(thrift.STRUCT, 0, 0),
Next: []dg.PathNode{
Expand All @@ -217,12 +217,12 @@ func MakeExampleRespBinary(msg, require_field, logid string) ([]byte, error) {
},
},
}
return dom.Marshal(DynamicgoOptions)
return dom.Marshal(dynamicgoOptions)
}

// MakeExampleReqBinary make a Thrift-Binary-Encoding request using ExampleReq DOM
// makeExampleReqBinary make a Thrift-Binary-Encoding request using ExampleReq DOM
// Except B, A and logid, which are reset everytime
func MakeExampleReqBinary(B bool, A, logid string) ([]byte, error) {
func makeExampleReqBinary(B bool, A, logid string) ([]byte, error) {
list := make([]dg.PathNode, SampleListSize+1)
list[0] = dg.PathNode{
Path: dg.NewPathIndex(0),
Expand Down Expand Up @@ -337,13 +337,13 @@ func MakeExampleReqBinary(B bool, A, logid string) ([]byte, error) {
},
},
}
return dom.Marshal(DynamicgoOptions)
return dom.Marshal(dynamicgoOptions)
}

const (
Method = "ExampleMethod2"
ReqMsg = "pending"
RespMsg = "ok"
method = "ExampleMethod2"
reqMsg = "pending"
respMsg = "ok"
)

// ExampleValueServiceImpl ...
Expand Down Expand Up @@ -373,7 +373,7 @@ func (g *ExampleValueServiceImpl) GenericCall(ctx context.Context, method string
// biz logic
func exampleServerHandler(request []byte) (resp []byte, err error) {
// wrap body as Value
req := dg.NewValue(ExampleReqDesc, request)
req := dg.NewValue(exampleReqDesc, request)
if err != nil {
return nil, err
}
Expand All @@ -382,7 +382,7 @@ func exampleServerHandler(request []byte) (resp []byte, err error) {
logid := ""
// if B == true then get logid and required_field
if b, err := req.FieldByName("B").Bool(); err == nil && b {
if e := req.GetByPath(BaseLogidPath...); e.Error() != "" {
if e := req.GetByPath(baseLogidPath...); e.Error() != "" {
return nil, e
} else {
logid, _ = e.String()
Expand All @@ -395,7 +395,7 @@ func exampleServerHandler(request []byte) (resp []byte, err error) {
}

// make response with checked values
return MakeExampleRespBinary(RespMsg, required_field, logid)
return makeExampleRespBinary(respMsg, required_field, logid)
}

var clientRespPool = sync.Pool{
Expand All @@ -414,14 +414,14 @@ func exampleClientHandler_Node(response []byte, log_id string) error {
if err != nil {
return err
}
if msg != RespMsg {
if msg != respMsg {
return errors.New("msg does not match")
}
require_field, err := resp.Field(2).String()
if err != nil {
return err
}
if require_field != ReqMsg {
if require_field != reqMsg {
return errors.New("require_field does not match")
}

Expand All @@ -434,29 +434,29 @@ func exampleClientHandler_DOM(response []byte, log_id string) error {
root.Node = dg.NewNode(dt.STRUCT, response)

// load **first layer** children
err := root.Load(false, DynamicgoOptions)
err := root.Load(false, dynamicgoOptions)
if err != nil {
return err
}
// spew.Dump(root) // -- only root.Next is set
// check node values by PathNode APIs
require_field2, err := root.Field(2, DynamicgoOptions).Node.String()
require_field2, err := root.Field(2, dynamicgoOptions).Node.String()
if err != nil {
return err
}
if require_field2 != ReqMsg {
if require_field2 != reqMsg {
return errors.New("require_field2 does not match")
}

// load **all layers** children
err = root.Load(true, DynamicgoOptions)
err = root.Load(true, dynamicgoOptions)
if err != nil {
return err
}

// spew.Dump(root) // -- every PathNode.Next will be set if it is a nesting-typed (LIST/SET/MAP/STRUCT)
// check node values by PathNode APIs
logid, err := root.Field(255, DynamicgoOptions).Field(1, DynamicgoOptions).Node.String()
logid, err := root.Field(255, dynamicgoOptions).Field(1, dynamicgoOptions).Node.String()
if err != nil {
return err
}
Expand Down

0 comments on commit 88b92ae

Please sign in to comment.