probe/service/ProbeClientService.go
crusader 6b52a1ef57 ing
2018-05-10 19:18:00 +09:00

74 lines
1.7 KiB
Go

package service
import (
"fmt"
"reflect"
cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry"
occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/probe/client/probe"
// For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation"
)
var ProbeClientServiceType = reflect.TypeOf((*ProbeClientService)(nil))
func init() {
cdr.RegisterType(ProbeClientServiceType)
}
type ProbeClientService struct {
RPCClientService
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
DiscoveryService *DiscoveryService `annotation:"@Inject()"`
EncryptionKey string
}
func (s *ProbeClientService) InitService() error {
if err := s.RPCClientService.InitService(); nil != err {
return fmt.Errorf("ProbeClientService: InitService failed %v", err)
}
return nil
}
func (s *ProbeClientService) StartService() error {
if err := s.RPCClientService.StartService(); nil != err {
return fmt.Errorf("ProbeClientService: StartService failed %v", err)
}
client, err := probe.New(s.HandleResponse, s.DiscoveryService)
if nil != err {
return fmt.Errorf("ProbeClientService: StartService failed %v", err)
}
s.client = client
if err := s.client.Start(); nil != err {
return fmt.Errorf("ProbeClientService: StartService failed %v", err)
}
return nil
}
func (s *ProbeClientService) StopService() {
s.RPCClientService.StopService()
}
func (s *ProbeClientService) DestroyService() {
s.RPCClientService.DestroyService()
}
func (s *ProbeClientService) HandleResponse(method string, param string) {
switch method {
case occp.HTTPResponseHeaderValue_Probe_Method_EncryptionKey:
s.EncryptionKey = param
case occp.HTTPResponseHeaderValue_Probe_Method_Delete:
}
}