overflow_probes/probe/probe.go
crusader b1adb63ea8 ing
2017-09-18 18:21:58 +09:00

76 lines
1.2 KiB
Go

package probe
import (
"context"
"git.loafle.net/commons_go/config"
"git.loafle.net/overflow/overflow_probes/probe/handler"
"git.loafle.net/overflow/overflow_probes/probe/handler/auth"
)
type Arguments struct {
Daemon *string
ConfigPath *string
}
var Args Arguments
func New() Probe {
p := &probe{}
return p
}
type Probe interface {
Start() error
Shutdown(ctx context.Context) error
}
type probe struct {
handler handler.Handler
probeConfig config.Configurator
}
func (p *probe) Start() error {
// conf := loadConfig(*configPath)
probeConf := loadProbeConfig(*Args.ConfigPath)
probeID := probeConf.GetString("id")
if "" == probeID {
a := auth.NewHandler()
a.Start()
} else {
}
return nil
}
func (p *probe) Shutdown(ctx context.Context) error {
return nil
}
func loadConfig(path string) config.Configurator {
conf := config.New()
conf.SetConfigName("config")
conf.AddConfigPath(path)
err := conf.ReadInConfig()
if nil != err {
panic(err)
}
return conf
}
func loadProbeConfig(path string) config.Configurator {
conf := config.New()
conf.SetConfigName("probe")
conf.AddConfigPath(path)
err := conf.ReadInConfig()
if nil != err {
panic(err)
}
return conf
}