initializer

This commit is contained in:
insanity@loafle.com 2017-05-19 11:23:03 +09:00
commit 127cd706b4
2 changed files with 111 additions and 0 deletions

62
.gitignore vendored Normal file
View File

@ -0,0 +1,62 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

49
initializer.go Normal file
View File

@ -0,0 +1,49 @@
package initializer_go
import (
"sync"
cm "loafle.com/overflow/agent_api/config_manager"
"google.golang.org/grpc"
)
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 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
}