overflow_probes/service/ConfigService.go

77 lines
1.4 KiB
Go
Raw Normal View History

2017-12-04 11:59:51 +00:00
package service
2017-12-08 12:01:38 +00:00
import (
2018-03-26 06:55:38 +00:00
"context"
"io/ioutil"
"path"
2017-12-08 12:01:38 +00:00
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdr "git.loafle.net/commons_go/di/registry"
2018-03-26 06:55:38 +00:00
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
"git.loafle.net/overflow/overflow_probes/config"
2017-12-08 12:01:38 +00:00
)
func init() {
2018-03-15 13:52:23 +00:00
cdr.RegisterType(reflect.TypeOf((*ConfigService)(nil)))
2017-12-08 12:01:38 +00:00
}
2017-12-04 11:59:51 +00:00
type ConfigService struct {
2018-03-15 13:52:23 +00:00
cda.TypeAnnotation `annotation:"@overFlow:Service()"`
2018-03-26 06:55:38 +00:00
oocmci.Service
}
func (cs *ConfigService) Start() error {
return nil
}
func (cs *ConfigService) Stop(ctx context.Context) error {
return nil
}
func (cs *ConfigService) loadConfigAll() error {
configDirPath := config.ConfigDirPath()
files, err := ioutil.ReadDir(configDirPath)
if nil != err {
return err
}
for _, file := range files {
if file.IsDir() == true {
if err := cs.loadConfigDir(path.Join(configDirPath, file.Name())); nil != err {
return err
}
}
}
return nil
}
func (cs *ConfigService) loadConfigDir(dirPath string) error {
files, err := ioutil.ReadDir(dirPath)
if nil != err {
return err
}
for _, file := range files {
filePath := path.Join(dirPath, file.Name())
if file.IsDir() == true {
cs.loadConfigDir(filePath)
} else {
_, err := ioutil.ReadFile(filePath)
if nil != err {
return err
}
// var m = config_manager.Config{}
// json.Unmarshal(b, &m)
// c.configs[file.Name()] = &m
}
}
return nil
2017-12-04 11:59:51 +00:00
}