initializer_go/initializer.go

61 lines
917 B
Go
Raw Normal View History

2017-05-19 02:23:03 +00:00
package initializer_go
import (
"google.golang.org/grpc"
2017-05-19 02:24:19 +00:00
cm "loafle.com/overflow/agent_api/config_manager"
"sync"
2017-05-19 02:23:03 +00:00
)
var (
2017-05-19 02:24:19 +00:00
once sync.Once
2017-05-19 02:23:03 +00:00
instance *Initializer
)
type Initializer struct {
2017-05-19 02:24:19 +00:00
gconf *cm.GlobalConfig
2017-05-19 02:23:03 +00:00
}
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
}
2017-05-19 02:24:19 +00:00
func Stop(res chan bool) {
GetInstance().stop()
res <- true
}
2017-05-19 02:23:03 +00:00
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 {
return nil, err
}
defer conn.Close()
return nil, nil
}
2017-05-19 02:24:19 +00:00
func (i *Initializer) stop() {
}