overflow_probe/initializer/initializer.go

60 lines
929 B
Go
Raw Normal View History

2017-08-04 02:32:31 +00:00
package initializer
2017-08-03 10:08:34 +00:00
import (
2017-08-04 02:37:00 +00:00
cm "git.loafle.net/overflow/overflow_probe/agent_api/config_manager"
2017-08-03 10:08:34 +00:00
"google.golang.org/grpc"
"sync"
)
var (
once sync.Once
instance *Initializer
)
type Initializer struct {
gconf *cm.GlobalConfig
}
func Start(ch chan string, conf *cm.GlobalConfig) error {
i := GetInstance()
i.gconf = conf
key, err := i.getSecretKey()
if err != nil {
return err
}
ch <- key
return nil
}
func Stop(res chan bool) {
GetInstance().stop()
res <- true
}
func GetInstance() *Initializer {
once.Do(func() {
instance = &Initializer{}
})
return instance
}
func (i *Initializer) getSecretKey() (string, error) {
//Todo. getting secret key from CentralAPI
addr := i.gconf.Central.Address + ":" + string(i.gconf.Central.Port)
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
2017-08-04 02:37:00 +00:00
return "", err
2017-08-03 10:08:34 +00:00
}
defer conn.Close()
2017-08-04 02:37:00 +00:00
return "", nil
2017-08-03 10:08:34 +00:00
}
func (i *Initializer) stop() {
}