Commit 3f0a1991fca052be37d14fa325a0e2297270d13b

Authored by zhangqijia
1 parent bca0b6f9

del test plugin

Makefile
... ... @@ -17,6 +17,9 @@ build:
17 17 go build -o bin/account cmd/http.go
18 18 go build -o bin/game cmd/game.go
19 19 go build -o bin/test test/client.go
  20 +regame:plugin
  21 + lsof -i:8849 | grep "game" | grep -v grep | awk '{print $$2}' | xargs -I {} kill -USR1 {}
  22 +
20 23 plugin:
21 24 #go build -ldflags -pluginpath="plugin/hot-1" --buildmode=plugin -o bin/plugin.so src/plugin/*.go
22 25 go build --buildmode=plugin -o bin/$(pname) src/plugin/*.go
... ...
plugin/plugin.go deleted
... ... @@ -1,11 +0,0 @@
1   -package main
2   -
3   -import (
4   - "fmt"
5   - "pro2d/src/components/net"
6   -)
7   -
8   -func IamPluginA(pkg net.MsgPkg) {
9   - fmt.Println("Hello, I am PluginB!")
10   - fmt.Println(pkg.Head.Length)
11   -}
plugin/plumain.go deleted
... ... @@ -1,32 +0,0 @@
1   -package main
2   -
3   -import (
4   - "fmt"
5   - "os"
6   - "plugin"
7   - "pro2d/src/components/net"
8   -)
9   -
10   -func main() {
11   - p, err := plugin.Open("./bin/plugin.so")
12   - if err != nil {
13   - fmt.Println("error open plugin: ", err)
14   - os.Exit(-1)
15   - }
16   - s, err := p.Lookup("IamPluginA")
17   - if err != nil {
18   - fmt.Println("error lookup IamPluginA: ", err)
19   - os.Exit(-1)
20   - }
21   - pkg1 := net.MsgPkg{
22   - Head: &net.Head{
23   - Length: 16,
24   - Cmd: 0,
25   - ErrCode: 0,
26   - },
27   - }
28   - if x, ok := s.(func(net.MsgPkg)); ok {
29   - x(pkg1)
30   - }
31   -
32   -}
src/actions/HttpAction.go
... ... @@ -106,7 +106,11 @@ func (h *HttpAction) Start() error {
106 106 models.InitAccountServerModels()
107 107  
108 108 //Etcd 初始化
109   - h.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd)
  109 + var err error
  110 + h.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd)
  111 + if err != nil {
  112 + return err
  113 + }
110 114 h.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.AccountConf.Name, conf.GlobalConf.AccountConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.AccountConf.IP, conf.GlobalConf.AccountConf.Port), 5)
111 115  
112 116 //gin初始化
... ...
src/components/etcd/etcd.go
... ... @@ -13,18 +13,18 @@ type EtcdClient struct {
13 13 etcd *clientv3.Client
14 14 }
15 15  
16   -func NewEtcdClient(conf *conf.Etcd) *EtcdClient {
  16 +func NewEtcdClient(conf *conf.Etcd) (*EtcdClient, error) {
17 17 cli, err := clientv3.New(clientv3.Config{
18 18 Endpoints: conf.Endpoints,
19 19 DialTimeout: time.Duration(conf.DialTimeout) * time.Second,
20 20 })
21 21 if err != nil {
22 22 logger.Error("etcd init err: %v", err)
23   - return nil
  23 + return nil, err
24 24 }
25 25 return &EtcdClient{
26 26 etcd: cli,
27   - }
  27 + }, nil
28 28 }
29 29  
30 30 func (e *EtcdClient)PutWithPrefix(prefix, key, val string) {
... ...
src/components/etcd/etcd_test.go
... ... @@ -11,7 +11,11 @@ import (
11 11 )
12 12  
13 13 func TestEtcdClient_GetByPrefix(t *testing.T) {
14   - etcd := NewEtcdClient(conf.GlobalConf.Etcd)
  14 + etcd, err := NewEtcdClient(conf.GlobalConf.Etcd)
  15 + if err != nil {
  16 + logger.Error(err)
  17 + return
  18 + }
15 19 gameInfo := etcd.GetByPrefix(conf.GlobalConf.AccountConf.Name)
16 20 for k, v := range gameInfo {
17 21 logger.Debug("game info key: %v val: %v", k, v)
... ...
src/components/net/server.go
... ... @@ -85,7 +85,7 @@ func (s *Server) LoadPlugin() {
85 85 //重新加载
86 86 _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath)
87 87 if err != nil {
88   - logger.Error("load plugin err: %v", err)
  88 + logger.Error("load plugin err: %v, %s", err, conf.GlobalConf.GameConf.PluginPath)
89 89 return
90 90 }
91 91 logger.Debug("load plugin success")
... ... @@ -97,11 +97,15 @@ func (s *Server)Start() error {
97 97 models.InitGameServerModels()
98 98  
99 99 //Etcd 初始化
100   - s.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd)
  100 + var err error
  101 + s.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd)
  102 + if err != nil {
  103 + return err
  104 + }
101 105 s.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.GameConf.Name, conf.GlobalConf.GameConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.GameConf.IP, conf.GlobalConf.GameConf.Port), 5)
102 106  
103 107 //初始化plugin
104   - _, err := plugin.Open(conf.GlobalConf.GameConf.PluginPath)
  108 + _, err = plugin.Open(conf.GlobalConf.GameConf.PluginPath)
105 109 if err != nil {
106 110 return err
107 111 }
... ...
src/plugin/RolePlugin.go
... ... @@ -34,7 +34,7 @@ func CreateRpc(msg *net.MsgPkg) (int32, proto.Message) {
34 34 }
35 35  
36 36 func LoginRpc(msg *net.MsgPkg) (int32, proto.Message) {
37   - logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body)
  37 + //logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body)
38 38 req := pb.LoginReq{}
39 39 if err := proto.Unmarshal(msg.Body, &req); err != nil {
40 40 logger.Error("loginRpc err: %v", err)
... ...