ipc_client/main.go
crusader a1f55549ac ing
2017-11-30 19:27:34 +09:00

81 lines
1.6 KiB
Go

package main
import (
"fmt"
"time"
cRPC "git.loafle.net/commons_go/rpc"
"git.loafle.net/overflow/ipc_client/rpc"
oodamdm "git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
"git.loafle.net/overflow/overflow_discovery/client"
)
func main() {
registry := cRPC.NewRegistry()
registry.RegisterService(new(rpc.DiscoveryService), "")
ch := client.NewClientHandler(registry)
sb := client.NewSocketBuilder("/tmp/discovery.sock")
c := client.New(ch, sb)
if err := c.Connect(); nil != err {
fmt.Printf("%v", err)
}
dz := newDiscoveryZone(true)
if err := c.Send("DiscoveryService.DiscoverZone", dz); nil != err {
fmt.Printf("%v\n", err)
}
time.Sleep(1 * time.Minute)
}
func newDiscoveryZone(includeDHost bool) *oodamdm.DiscoveryZone {
dz := &oodamdm.DiscoveryZone{
ExcludePatterns: []string{},
}
if includeDHost {
dz.DiscoveryHost = newDiscoveryHost(true)
}
return dz
}
func newDiscoveryHost(includeDPort bool) *oodamdm.DiscoveryHost {
dh := &oodamdm.DiscoveryHost{
FirstScanRange: "192.168.1.1",
LastScanRange: "192.168.1.254",
ExcludeHosts: []string{},
}
if includeDPort {
dh.DiscoveryPort = newDiscoveryPort(true)
}
return dh
}
func newDiscoveryPort(includeDService bool) *oodamdm.DiscoveryPort {
dp := &oodamdm.DiscoveryPort{
FirstScanRange: 1,
LastScanRange: 1024,
ExcludePorts: []int{},
IncludeTCP: true,
IncludeUDP: true,
}
if includeDService {
dp.DiscoveryService = newDiscoveryService()
}
return dp
}
func newDiscoveryService() *oodamdm.DiscoveryService {
ds := &oodamdm.DiscoveryService{
IncludeServices: []string{},
}
return ds
}