[add] process xiang.server.*
This commit is contained in:
parent
5332efc532
commit
a99d75a91b
2 changed files with 71 additions and 0 deletions
57
server/process.go
Normal file
57
server/process.go
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/yaoapp/gou"
|
||||||
|
"github.com/yaoapp/kun/exception"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gou.RegisterProcessHandler("xiang.server.Start", ProcessStart)
|
||||||
|
gou.RegisterProcessHandler("xiang.server.Connect", ProcessConnect)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessStart xiang.server.Start
|
||||||
|
func ProcessStart(process *gou.Process) interface{} {
|
||||||
|
process.ValidateArgNums(1)
|
||||||
|
|
||||||
|
name := process.ArgsString(0)
|
||||||
|
serv, has := gou.Sockets[name]
|
||||||
|
if !has {
|
||||||
|
exception.New("%s does not load", 400, name).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []interface{}{}
|
||||||
|
if process.NumOfArgs() > 1 {
|
||||||
|
args = process.Args[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if serv.Mode != "server" {
|
||||||
|
exception.New("%s mode [%s] not server", 400, name, serv.Mode).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
|
serv.Start(args...)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessConnect xiang.server.Connect
|
||||||
|
func ProcessConnect(process *gou.Process) interface{} {
|
||||||
|
process.ValidateArgNums(1)
|
||||||
|
|
||||||
|
name := process.ArgsString(0)
|
||||||
|
serv, has := gou.Sockets[name]
|
||||||
|
if !has {
|
||||||
|
exception.New("%s does not load", 400, name).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []interface{}{}
|
||||||
|
if process.NumOfArgs() > 1 {
|
||||||
|
args = process.Args[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if serv.Mode != "client" {
|
||||||
|
exception.New("%s mode [%s] not server", 400, name, serv.Mode).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
|
serv.Connect(args...)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,20 @@ func TestLoad(t *testing.T) {
|
||||||
check(t)
|
check(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessStart(t *testing.T) {
|
||||||
|
Load(config.Conf)
|
||||||
|
// assert.NotPanics(t, func() {
|
||||||
|
// gou.NewProcess("xiang.server.Start", "rfid").Run()
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessConnect(t *testing.T) {
|
||||||
|
Load(config.Conf)
|
||||||
|
// assert.NotPanics(t, func() {
|
||||||
|
// gou.NewProcess("xiang.server.Connect", "rfid_client").Run()
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
func check(t *testing.T) {
|
func check(t *testing.T) {
|
||||||
keys := []string{}
|
keys := []string{}
|
||||||
for key := range gou.Sockets {
|
for key := range gou.Sockets {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue