-
Notifications
You must be signed in to change notification settings - Fork 9
/
config_watcher.go
37 lines (32 loc) · 1.06 KB
/
config_watcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package config
import (
"errors"
"fmt"
"time"
"github.com/madappgang/identifo/v2/model"
"github.com/madappgang/identifo/v2/storage"
)
const defaultS3PollInterval = time.Minute // poll new updates every minute
func NewConfigWatcher(settings model.FileStorageSettings) (model.ConfigurationWatcher, error) {
filename := settings.FileName()
switch settings.Type {
case model.FileStorageTypeS3:
if len(settings.S3.Bucket) == 0 {
return nil, errors.New("empty storage settings for S3 type")
}
settings.S3.Key = settings.Dir() // remove filename from key to keep dir only
case model.FileStorageTypeLocal:
if len(settings.Local.Path) == 0 {
return nil, errors.New("empty storage settings for File storage type")
}
settings.Local.Path = settings.Dir() // remove filename from key to keep dir only
default:
return nil, fmt.Errorf("Unsupported config storage type: %v", settings.Type)
}
fs, err := storage.NewFS(settings)
if err != nil {
return nil, err
}
watcher := storage.NewFSWatcher(fs, []string{filename}, defaultS3PollInterval)
return watcher, nil
}