54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"reflect"
|
||
|
|
||
|
cda "git.loafle.net/commons/di-go/annotation"
|
||
|
cdr "git.loafle.net/commons/di-go/registry"
|
||
|
logging "git.loafle.net/commons/logging-go"
|
||
|
crc "git.loafle.net/commons/rpc-go/client"
|
||
|
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
||
|
"git.loafle.net/overflow/probe/client/central"
|
||
|
)
|
||
|
|
||
|
var DataClientServiceType = reflect.TypeOf((*DataClientService)(nil))
|
||
|
|
||
|
func init() {
|
||
|
cdr.RegisterType(DataClientServiceType)
|
||
|
}
|
||
|
|
||
|
type DataClientService struct {
|
||
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||
|
|
||
|
client *crc.Client
|
||
|
}
|
||
|
|
||
|
func (s *DataClientService) InitService() error {
|
||
|
client, err := central.NewData()
|
||
|
if nil != err {
|
||
|
return err
|
||
|
}
|
||
|
s.client = client
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (s *DataClientService) StartService() error {
|
||
|
if err := s.client.Start(); nil != err {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (s *DataClientService) StopService() {
|
||
|
if err := s.client.Stop(context.Background()); nil != err {
|
||
|
logging.Logger().Error(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *DataClientService) DestroyService() {
|
||
|
s.client = nil
|
||
|
}
|