mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
实现网关服务器不同版本客户端协议代理功能
This commit is contained in:
33
gate/client_proto/client_proto_gen_test.go
Normal file
33
gate/client_proto/client_proto_gen_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package client_proto
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientProtoGen(t *testing.T) {
|
||||
clientCmdProtoMap := NewClientCmdProtoMap()
|
||||
|
||||
fileData := "package client_proto\n"
|
||||
fileData += "\n"
|
||||
fileData += "import (\n"
|
||||
fileData += "\"hk4e/gate/client_proto/proto\"\n"
|
||||
fileData += "pb \"google.golang.org/protobuf/proto\"\n"
|
||||
fileData += ")\n"
|
||||
fileData += "\n"
|
||||
fileData += "func (c *ClientCmdProtoMap) GetClientProtoObjByCmdName(cmdName string) pb.Message {\n"
|
||||
fileData += "switch cmdName {\n"
|
||||
for cmdName := range clientCmdProtoMap.clientCmdNameCmdIdMap {
|
||||
fileData += "case \"" + cmdName + "\":\nreturn new(proto." + cmdName + ")\n"
|
||||
}
|
||||
fileData += "default:\n"
|
||||
fileData += "return nil\n"
|
||||
fileData += "}\n"
|
||||
fileData += "}\n"
|
||||
fileData += "\n"
|
||||
|
||||
err := os.WriteFile("../client_proto_gen.go", []byte(fileData), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user