mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
新增测试模块
This commit is contained in:
21
Test2/Helloworld/.vscode/launch.json
vendored
Normal file
21
Test2/Helloworld/.vscode/launch.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
Test2/Helloworld/.vscode/settings.json
vendored
Normal file
3
Test2/Helloworld/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"go.gopath": "${workspaceRoot}/../../../../../"
|
||||
}
|
||||
34
Test2/Helloworld/SubNet1_Service.go
Normal file
34
Test2/Helloworld/SubNet1_Service.go
Normal file
@@ -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
|
||||
}
|
||||
40
Test2/Helloworld/SubNet1_Service1.go
Normal file
40
Test2/Helloworld/SubNet1_Service1.go
Normal file
@@ -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
|
||||
}
|
||||
31
Test2/Helloworld/SubNet1_Service2.go
Normal file
31
Test2/Helloworld/SubNet1_Service2.go
Normal file
@@ -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
|
||||
}
|
||||
31
Test2/Helloworld/SubNet2_Service1.go
Normal file
31
Test2/Helloworld/SubNet2_Service1.go
Normal file
@@ -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
|
||||
}
|
||||
4
Test2/Helloworld/build.bat
Normal file
4
Test2/Helloworld/build.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
SET CGO_ENABLED=0
|
||||
SET GOOS=linux
|
||||
SET GOARCH=amd64
|
||||
go build -v
|
||||
54
Test2/Helloworld/config/cluster.json
Normal file
54
Test2/Helloworld/config/cluster.json
Normal file
@@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
44
Test2/Helloworld/config/nodeconfig.json
Normal file
44
Test2/Helloworld/config/nodeconfig.json
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
26
Test2/Helloworld/main.go
Normal file
26
Test2/Helloworld/main.go
Normal file
@@ -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()
|
||||
}
|
||||
10
Test2/Helloworld/workspace.code-workspace
Normal file
10
Test2/Helloworld/workspace.code-workspace
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"http.systemCertificates": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user