From 9623cd27357d023b1808c18c12bef02ba9757b06 Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Mon, 23 Sep 2019 14:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test2/Helloworld/.vscode/launch.json | 21 +++++++++ Test2/Helloworld/.vscode/settings.json | 3 ++ Test2/Helloworld/SubNet1_Service.go | 34 ++++++++++++++ Test2/Helloworld/SubNet1_Service1.go | 40 +++++++++++++++++ Test2/Helloworld/SubNet1_Service2.go | 31 +++++++++++++ Test2/Helloworld/SubNet2_Service1.go | 31 +++++++++++++ Test2/Helloworld/build.bat | 4 ++ Test2/Helloworld/config/cluster.json | 54 +++++++++++++++++++++++ Test2/Helloworld/config/nodeconfig.json | 44 ++++++++++++++++++ Test2/Helloworld/main.go | 26 +++++++++++ Test2/Helloworld/workspace.code-workspace | 10 +++++ 11 files changed, 298 insertions(+) create mode 100644 Test2/Helloworld/.vscode/launch.json create mode 100644 Test2/Helloworld/.vscode/settings.json create mode 100644 Test2/Helloworld/SubNet1_Service.go create mode 100644 Test2/Helloworld/SubNet1_Service1.go create mode 100644 Test2/Helloworld/SubNet1_Service2.go create mode 100644 Test2/Helloworld/SubNet2_Service1.go create mode 100644 Test2/Helloworld/build.bat create mode 100644 Test2/Helloworld/config/cluster.json create mode 100644 Test2/Helloworld/config/nodeconfig.json create mode 100644 Test2/Helloworld/main.go create mode 100644 Test2/Helloworld/workspace.code-workspace diff --git a/Test2/Helloworld/.vscode/launch.json b/Test2/Helloworld/.vscode/launch.json new file mode 100644 index 0000000..cf043fa --- /dev/null +++ b/Test2/Helloworld/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + + "configurations": [ + { + "name": "N_All", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceRoot}/main.go", + "env": { + "GOPATH":"${workspaceRoot}/../../../../../../" + }, + "args": ["NodeId=1"], + "output": "./OriginServer.exe" + } + ] +} \ No newline at end of file diff --git a/Test2/Helloworld/.vscode/settings.json b/Test2/Helloworld/.vscode/settings.json new file mode 100644 index 0000000..ef5cde8 --- /dev/null +++ b/Test2/Helloworld/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "go.gopath": "${workspaceRoot}/../../../../../" +} diff --git a/Test2/Helloworld/SubNet1_Service.go b/Test2/Helloworld/SubNet1_Service.go new file mode 100644 index 0000000..11f6a74 --- /dev/null +++ b/Test2/Helloworld/SubNet1_Service.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + + "github.com/duanhf2012/origin/cluster" + "github.com/duanhf2012/origin/originnode" + "github.com/duanhf2012/origin/service" +) + +type SubNet1_Service struct { + service.BaseService +} + +func init() { + originnode.InitService(&SubNet1_Service{}) +} + +//OnInit ... +func (ws *SubNet1_Service) OnInit() error { + + return nil +} + +//OnRun ... +func (ws *SubNet1_Service) OnRun() bool { + var in InputData + var ret int + in.A1 = 10 + in.A2 = 20 + err := cluster.Call("SubNet2_Service1.RPC_Multi", &in, &ret) + fmt.Printf("%+v", err) + return false +} diff --git a/Test2/Helloworld/SubNet1_Service1.go b/Test2/Helloworld/SubNet1_Service1.go new file mode 100644 index 0000000..88f7173 --- /dev/null +++ b/Test2/Helloworld/SubNet1_Service1.go @@ -0,0 +1,40 @@ +package main + +import ( + "github.com/duanhf2012/origin/originnode" + "github.com/duanhf2012/origin/service" +) + +type InputData struct { + A1 int + A2 int +} + +type SubNet1_Service1 struct { + service.BaseService +} + +func init() { + originnode.InitService(&SubNet1_Service1{}) +} + +//OnInit ... +func (ws *SubNet1_Service1) OnInit() error { + + return nil +} + +//OnRun ... +func (ws *SubNet1_Service1) OnRun() bool { + return false +} + +//服务要对外的接口规划如下: +//RPC_MethodName(arg *DataType1, ret *DataType2) error +//如果不符合规范,在加载服务时,该函数将不会被映射,其他服务将不允能调用。 +func (slf *SubNet1_Service1) RPC_Add(arg *InputData, ret *int) error { + + *ret = arg.A1 + arg.A2 + + return nil +} diff --git a/Test2/Helloworld/SubNet1_Service2.go b/Test2/Helloworld/SubNet1_Service2.go new file mode 100644 index 0000000..83e87e1 --- /dev/null +++ b/Test2/Helloworld/SubNet1_Service2.go @@ -0,0 +1,31 @@ +package main + +import ( + "github.com/duanhf2012/origin/originnode" + "github.com/duanhf2012/origin/service" +) + +type SubNet1_Service2 struct { + service.BaseService +} + +func init() { + originnode.InitService(&SubNet1_Service2{}) +} + +//OnInit ... +func (ws *SubNet1_Service2) OnInit() error { + return nil +} + +//OnRun ... +func (ws *SubNet1_Service2) OnRun() bool { + return false +} + +func (slf *SubNet1_Service2) RPC_Sub(arg *InputData, ret *int) error { + + *ret = arg.A1 - arg.A2 + + return nil +} diff --git a/Test2/Helloworld/SubNet2_Service1.go b/Test2/Helloworld/SubNet2_Service1.go new file mode 100644 index 0000000..78e7d54 --- /dev/null +++ b/Test2/Helloworld/SubNet2_Service1.go @@ -0,0 +1,31 @@ +package main + +import ( + "github.com/duanhf2012/origin/originnode" + "github.com/duanhf2012/origin/service" +) + +type SubNet2_Service1 struct { + service.BaseService +} + +func init() { + originnode.InitService(&SubNet2_Service1{}) +} + +//OnInit ... +func (ws *SubNet2_Service1) OnInit() error { + return nil +} + +//OnRun ... +func (ws *SubNet2_Service1) OnRun() bool { + return false +} + +func (slf *SubNet2_Service1) RPC_Multi(arg *InputData, ret *int) error { + + *ret = arg.A1 * arg.A2 + + return nil +} diff --git a/Test2/Helloworld/build.bat b/Test2/Helloworld/build.bat new file mode 100644 index 0000000..d55ef7c --- /dev/null +++ b/Test2/Helloworld/build.bat @@ -0,0 +1,4 @@ +SET CGO_ENABLED=0 +SET GOOS=linux +SET GOARCH=amd64 +go build -v \ No newline at end of file diff --git a/Test2/Helloworld/config/cluster.json b/Test2/Helloworld/config/cluster.json new file mode 100644 index 0000000..9ccedf6 --- /dev/null +++ b/Test2/Helloworld/config/cluster.json @@ -0,0 +1,54 @@ +{ + "SubNet": [{ + "Remark": "Manual,Full,Auto", + "SubNetMode": "Full", + "SubNetName": "SubNet1", + "PublicServiceList": ["logiclog"], + "NodeList": [{ + "NodeID": 1, + "NodeName": "N_Node1", + "ServiceList": [ + "HttpServerService", + "SubNet1_Service", + "SubNet1_Service1" + ], + "ClusterNode":["SubNet2.N_Node1","N_Node2"] + }, + { + "NodeID": 2, + "NodeName": "N_Node2", + "ServiceList": [ + "SubNet1_Service2" + ], + "ClusterNode":[] + } + ] + }, + + + { + "Remark": "Manual,Full,Auto", + "SubNetMode": "Full", + "SubNetName": "SubNet2", + "PublicServiceList": ["logiclog"], + "NodeList": [{ + "NodeID": 3, + "NodeName": "N_Node1", + "ServiceList": [ + "SubNet2_Service1" + ], + "ClusterNode":["URQ.N_Node1"] + } + ] + } + ] +} + + + + + + + + + diff --git a/Test2/Helloworld/config/nodeconfig.json b/Test2/Helloworld/config/nodeconfig.json new file mode 100644 index 0000000..b8cae4b --- /dev/null +++ b/Test2/Helloworld/config/nodeconfig.json @@ -0,0 +1,44 @@ +{ +"Public":{ + "LogLevel":1, + "HttpPort":9400, + "WSPort":9500, + + "CAFile":[ + { + "CertFile":"", + "KeyFile":"" + }, + { + "CertFile":"", + "KeyFile":"" + } + ], + + "Environment":"FS_Dev_LFY", + "IsListenLog":1, + "IsSendErrorMail":0 +}, + +"NodeList":[ +{ + "NodeID":1, + "NodeAddr": "127.0.0.1:8081", + "LogLevel":1, + "HttpPort":7001, + "WSPort":7000, + "CertFile":"", + "KeyFile":"" +}, +{ + "NodeID":2, + "NodeAddr": "127.0.0.1:8082" +} +, +{ + "NodeID":3, + "NodeAddr": "127.0.0.1:8083" +} +] + +} \ No newline at end of file diff --git a/Test2/Helloworld/main.go b/Test2/Helloworld/main.go new file mode 100644 index 0000000..90842ef --- /dev/null +++ b/Test2/Helloworld/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "github.com/duanhf2012/origin/cluster" + "github.com/duanhf2012/origin/originnode" + "github.com/duanhf2012/origin/sysservice" +) + +func main() { + + node := originnode.NewOriginNode() + if node == nil { + return + } + + nodeCfg, _ := cluster.ReadNodeConfig("./config/nodeconfig.json", cluster.GetNodeId()) + httpserver := sysservice.NewHttpServerService(nodeCfg.HttpPort) // http服务 + for _, ca := range nodeCfg.CAFile { + httpserver.SetHttps(ca.CertFile, ca.KeyFile) + } + httpserver.SetPrintRequestTime(true) + + node.SetupService(httpserver) + node.Init() + node.Start() +} diff --git a/Test2/Helloworld/workspace.code-workspace b/Test2/Helloworld/workspace.code-workspace new file mode 100644 index 0000000..1283249 --- /dev/null +++ b/Test2/Helloworld/workspace.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "http.systemCertificates": false + } +} \ No newline at end of file