From 9a4e4cea170accb455d9c29a3038a382a5ebee88 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 22 Oct 2020 10:56:22 +0800 Subject: [PATCH] init --- server/analyseapi/app.go | 32 ++++++++++++++++++++ server/analyseapi/go.mod | 23 +++++++++++++++ server/analyseapi/makefile | 11 +++++++ server/analyseapi/metamgr.go | 50 ++++++++++++++++++++++++++++++++ server/analyseapi/metawrap.go | 7 +++++ server/tools/protobuild/mt.proto | 13 +++++++++ 6 files changed, 136 insertions(+) create mode 100644 server/analyseapi/app.go create mode 100644 server/analyseapi/go.mod create mode 100644 server/analyseapi/makefile create mode 100644 server/analyseapi/metamgr.go create mode 100644 server/analyseapi/metawrap.go create mode 100644 server/tools/protobuild/mt.proto diff --git a/server/analyseapi/app.go b/server/analyseapi/app.go new file mode 100644 index 0000000..84300c2 --- /dev/null +++ b/server/analyseapi/app.go @@ -0,0 +1,32 @@ +package main + +import "q5" +import "f5" +import "fmt" +import "time" + +type App_ struct { + f5.App_ +} + +var App *App_ + +func (this *App_) Init() { + f5.App = &this.App_ + this.App_.Init() + G.MetaMgr = &MetaMgr{} + G.MetaMgr.Init() + f5.Timer().AddRepeatTimer( + 1000 * 5, + func (params *q5.XParams) { + + }, + func (params *q5.XParams) { + fmt.Println("hello", time.Now()) + }) +} + +func (this *App_) UnInit() { + G.MetaMgr.UnInit() + this.App_.UnInit() +} diff --git a/server/analyseapi/go.mod b/server/analyseapi/go.mod new file mode 100644 index 0000000..632d09a --- /dev/null +++ b/server/analyseapi/go.mod @@ -0,0 +1,23 @@ +module analyseapi + +go 1.11 + +require q5 v1.0.0 + +require f5 v1.0.0 + +require mt v1.0.0 + +require ( + github.com/golang/protobuf v1.4.2 + google.golang.org/protobuf v1.23.0 + im v1.0.0 +) + +replace q5 => ../../third_party/q5 + +replace f5 => ../../third_party/f5 + +replace im => ../../third_party/f5/im + +replace mt => ./mt diff --git a/server/analyseapi/makefile b/server/analyseapi/makefile new file mode 100644 index 0000000..0cbfb16 --- /dev/null +++ b/server/analyseapi/makefile @@ -0,0 +1,11 @@ +compile: + @. /etc/profile + + protoc --proto_path=../tools/protobuild --go_out=./mt ../tools/protobuild/mt.proto + @export GOPROXY=https://goproxy.io + @go build -gcflags=all="-N -l" -o ../bin/analyseapi + @echo "compile done" + +clean: + @rm -f ../bin/analyseapi + @echo "clean done" diff --git a/server/analyseapi/metamgr.go b/server/analyseapi/metamgr.go new file mode 100644 index 0000000..c299e60 --- /dev/null +++ b/server/analyseapi/metamgr.go @@ -0,0 +1,50 @@ +package main + +import "f5" +import "mt" +//import "fmt" +//import "reflect" + +const ( + MT_SERVER_INFO = 0 + MT_MAX +) + +type MetaMgr struct { + f5.MetaMgr +} + +func (this *MetaMgr) Init() { + this.MetaMgr.Init() + metaClasses := &[]f5.MetaClass{ + f5.MetaClass{ + PrimKey: "InstanceId", + FileName: "/var/data/conf_test/mail/mail.cluster.json", + Idx: MT_SERVER_INFO, + RawMeta: (*mt.ServerInfoMetas)(nil), + WrapMeta: (*MtwServerInfo)(nil)}, + } + this.MetaMgr.RegisterMetaClasses(metaClasses) +} + +func (this *MetaMgr) UnInit() { + this.MetaMgr.UnInit() +} + +func (this *MetaMgr) GetServer(instance_id int32) *MtwServerInfo { + v, ok := this.MetaMgr.GetMetaById(MT_SERVER_INFO, instance_id).(*MtwServerInfo) + if ok { + return v + } else { + return nil + } +} + +func (this *MetaMgr) GetServerList() []*MtwServerInfo { + v, ok := this.MetaMgr.GetMetaList(MT_SERVER_INFO).([]*MtwServerInfo) + if ok { + return v + } else { + return nil + } +} diff --git a/server/analyseapi/metawrap.go b/server/analyseapi/metawrap.go new file mode 100644 index 0000000..e67f656 --- /dev/null +++ b/server/analyseapi/metawrap.go @@ -0,0 +1,7 @@ +package main + +import "mt" + +type MtwServerInfo struct { + *mt.ServerInfo +} diff --git a/server/tools/protobuild/mt.proto b/server/tools/protobuild/mt.proto new file mode 100644 index 0000000..d30edec --- /dev/null +++ b/server/tools/protobuild/mt.proto @@ -0,0 +1,13 @@ +package mt; + +message ServerInfo +{ + optional int32 instance_id = 1; + optional string listen_ip = 2; + optional int32 listen_port = 3; +} + +message ServerInfoMetas +{ + repeated ServerInfo values = 1; +}