service -> configuration

This commit is contained in:
emile 2015-09-08 00:15:14 +02:00
parent 7fcc4761da
commit cef926379c
5 changed files with 53 additions and 51 deletions

20
file.go
View file

@ -14,7 +14,7 @@ type FileProvider struct {
Filename string
}
func (provider *FileProvider) Provide(serviceChan chan<- *Service){
func (provider *FileProvider) Provide(configurationChan chan<- *Configuration){
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Println(err)
@ -37,9 +37,9 @@ func (provider *FileProvider) Provide(serviceChan chan<- *Service){
case event := <-watcher.Events:
if(strings.Contains(event.Name,file.Name())){
log.Println("File event:", event)
service := provider.LoadFileConfig(file.Name())
if(service != nil) {
serviceChan <- service
configuration := provider.LoadFileConfig(file.Name())
if(configuration != nil) {
configurationChan <- configuration
}
}
case error := <-watcher.Errors:
@ -58,17 +58,17 @@ func (provider *FileProvider) Provide(serviceChan chan<- *Service){
}
service:= provider.LoadFileConfig(file.Name())
serviceChan <- service
configuration := provider.LoadFileConfig(file.Name())
configurationChan <- configuration
<-done
}
func (provider *FileProvider) LoadFileConfig(filename string) *Service {
service := new(Service)
if _, err := toml.DecodeFile(filename, service); err != nil {
func (provider *FileProvider) LoadFileConfig(filename string) *Configuration {
configuration := new(Configuration)
if _, err := toml.DecodeFile(filename, configuration); err != nil {
log.Println("Error reading file:", err)
return nil
}
return service
return configuration
}