package service import ( "log" "reflect" oa "git.loafle.net/overflow/annotation-go" od "git.loafle.net/overflow/di-go" omd "git.loafle.net/overflow/model/discovery" "git.loafle.net/overflow_scanner/probe/discovery" ) func init() { od.RegisterType(DiscoveryServiceType) } var DiscoveryServiceType = reflect.TypeOf((*DiscoveryService)(nil)) type DiscoveryService struct { oa.TypeAnnotation `annotation:"@Injectable('name': 'DiscoveryService') @Service()"` Discoverer discovery.Discoverer `annotation:"@Resource('name': 'Discoverer')"` } func (s *DiscoveryService) InitService() error { return nil } func (s *DiscoveryService) StartService() error { go func() { for { select { case msg, ok := <-s.Discoverer.Message(): if !ok { return } log.Print(msg) } } }() return nil } func (s *DiscoveryService) StopService() { s.Discoverer.Shutdown() } func (s *DiscoveryService) DestroyService() { } func (s *DiscoveryService) DiscoverHost(requesterID string, zone *omd.Zone, dh *omd.DiscoverHost) error { s.Discoverer.DiscoverHost(requesterID, zone, dh) return nil } func (s *DiscoveryService) DiscoverPort(requesterID string, host *omd.Host, dp *omd.DiscoverPort) error { s.Discoverer.DiscoverPort(requesterID, host, dp) return nil } func (s *DiscoveryService) DiscoverService(requesterID string, port *omd.Port, ds *omd.DiscoverService) error { s.Discoverer.DiscoverService(requesterID, port, ds) return nil } func (s *DiscoveryService) StopDiscover() error { return nil }