ing
This commit is contained in:
@@ -17,23 +17,25 @@ import (
|
||||
"github.com/grandcat/zeroconf"
|
||||
)
|
||||
|
||||
func Scan(discoverySession session.DiscoverySession) {
|
||||
func Scan(discoverySession session.DiscoverySession) error {
|
||||
serviceEntries, err := browse("_services._dns-sd._udp", "local")
|
||||
if nil != err {
|
||||
log.Print("Cannot find service ", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
metaIPTypeEnum := omm.ToMetaIPTypeEnum(discoverySession.Zone().MetaIPType)
|
||||
|
||||
SERVICE_LOOP:
|
||||
for _, serviceEntry := range serviceEntries {
|
||||
name := removeDomainName(serviceEntry.Instance, serviceEntry.Domain)
|
||||
entries, _err := browse(name, serviceEntry.Domain)
|
||||
if nil != _err {
|
||||
log.Print("Cannot find entry ", _err)
|
||||
return
|
||||
continue SERVICE_LOOP
|
||||
}
|
||||
|
||||
LOOP:
|
||||
ENTRY_LOOP:
|
||||
for _, entry := range entries {
|
||||
// log.Print("serviceEntry ", entry)
|
||||
|
||||
@@ -73,7 +75,7 @@ func Scan(discoverySession session.DiscoverySession) {
|
||||
})
|
||||
|
||||
if 1 > port {
|
||||
continue LOOP
|
||||
continue ENTRY_LOOP
|
||||
}
|
||||
|
||||
p := discoverySession.AddPort(&omd.Port{
|
||||
@@ -103,7 +105,7 @@ func Scan(discoverySession session.DiscoverySession) {
|
||||
})
|
||||
|
||||
if 1 > port {
|
||||
continue LOOP
|
||||
continue ENTRY_LOOP
|
||||
}
|
||||
|
||||
p := discoverySession.AddPort(&omd.Port{
|
||||
@@ -124,6 +126,8 @@ func Scan(discoverySession session.DiscoverySession) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeDomainName(instance string, domain string) (service string) {
|
||||
|
||||
@@ -34,19 +34,23 @@ func TestScan(t *testing.T) {
|
||||
discoverySession session.DiscoverySession
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "1",
|
||||
args: args{
|
||||
discoverySession: s,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
Scan(tt.args.discoverySession)
|
||||
if err := Scan(tt.args.discoverySession); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user