initializer_go/initializer.go
insanity@loafle.com 560a16b6fe initializer
2017-05-19 11:24:19 +09:00

61 lines
917 B
Go

package initializer_go
import (
"google.golang.org/grpc"
cm "loafle.com/overflow/agent_api/config_manager"
"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 {
return nil, err
}
defer conn.Close()
return nil, nil
}
func (i *Initializer) stop() {
}