review
This commit is contained in:
parent
c2bcf153e9
commit
0e4b36035c
60
file.go
60
file.go
@ -13,6 +13,36 @@ type FileBackend struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b FileBackend) getStoredData(watch bool) (<-chan *StoredData, <-chan error) {
|
||||||
|
dataCh := make(chan *StoredData)
|
||||||
|
errCh := make(chan error)
|
||||||
|
go func() {
|
||||||
|
sendStoredData(b.Path, dataCh, errCh)
|
||||||
|
if !watch {
|
||||||
|
close(dataCh)
|
||||||
|
close(errCh)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if !watch {
|
||||||
|
return dataCh, errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
watcher, err := fsnotify.NewWatcher()
|
||||||
|
if err != nil {
|
||||||
|
errCh <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
go loopFile(b.Path, watcher, dataCh, errCh)
|
||||||
|
|
||||||
|
err = watcher.Add(b.Path)
|
||||||
|
if err != nil {
|
||||||
|
errCh <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataCh, errCh
|
||||||
|
}
|
||||||
|
|
||||||
func getStoredDataFromFile(path string) (*StoredData, error) {
|
func getStoredDataFromFile(path string) (*StoredData, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -54,33 +84,3 @@ func loopFile(path string, watcher *fsnotify.Watcher, dataCh chan *StoredData, e
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b FileBackend) getStoredData(watch bool) (<-chan *StoredData, <-chan error) {
|
|
||||||
dataCh := make(chan *StoredData)
|
|
||||||
errCh := make(chan error)
|
|
||||||
go func() {
|
|
||||||
sendStoredData(b.Path, dataCh, errCh)
|
|
||||||
if !watch {
|
|
||||||
close(dataCh)
|
|
||||||
close(errCh)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if !watch {
|
|
||||||
return dataCh, errCh
|
|
||||||
}
|
|
||||||
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
|
||||||
if err != nil {
|
|
||||||
errCh <- err
|
|
||||||
}
|
|
||||||
|
|
||||||
go loopFile(b.Path, watcher, dataCh, errCh)
|
|
||||||
|
|
||||||
err = watcher.Add(b.Path)
|
|
||||||
if err != nil {
|
|
||||||
errCh <- err
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataCh, errCh
|
|
||||||
}
|
|
||||||
|
|||||||
84
kv.go
84
kv.go
@ -17,6 +17,48 @@ import (
|
|||||||
|
|
||||||
const storeKey = "traefik/acme/account/object"
|
const storeKey = "traefik/acme/account/object"
|
||||||
|
|
||||||
|
// KVBackend represents a Key/Value pair backend
|
||||||
|
type KVBackend struct {
|
||||||
|
Name string
|
||||||
|
Client []string
|
||||||
|
Config *store.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b KVBackend) getStoredData(watch bool) (<-chan *StoredData, <-chan error) {
|
||||||
|
dataCh := make(chan *StoredData)
|
||||||
|
errCh := make(chan error)
|
||||||
|
|
||||||
|
backend, err := register(b.Name)
|
||||||
|
if err != nil {
|
||||||
|
go func() {
|
||||||
|
errCh <- err
|
||||||
|
}()
|
||||||
|
return dataCh, errCh
|
||||||
|
}
|
||||||
|
kvStore, err := valkeyrie.NewStore(
|
||||||
|
backend,
|
||||||
|
b.Client,
|
||||||
|
b.Config,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
go func() {
|
||||||
|
errCh <- err
|
||||||
|
}()
|
||||||
|
return dataCh, errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
if !watch {
|
||||||
|
go getSingleData(kvStore, dataCh, errCh)
|
||||||
|
return dataCh, errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
go loopKV(watch, kvStore, dataCh, errCh)
|
||||||
|
|
||||||
|
return dataCh, errCh
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func getStoredDataFromGzip(value []byte) (*StoredData, error) {
|
func getStoredDataFromGzip(value []byte) (*StoredData, error) {
|
||||||
data := &StoredData{}
|
data := &StoredData{}
|
||||||
|
|
||||||
@ -38,13 +80,6 @@ func getStoredDataFromGzip(value []byte) (*StoredData, error) {
|
|||||||
return storedData, nil
|
return storedData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVBackend represents a Key/Value pair backend
|
|
||||||
type KVBackend struct {
|
|
||||||
Name string
|
|
||||||
Client []string
|
|
||||||
Config *store.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
func register(backend string) (store.Backend, error) {
|
func register(backend string) (store.Backend, error) {
|
||||||
switch backend {
|
switch backend {
|
||||||
case Consul:
|
case Consul:
|
||||||
@ -108,38 +143,3 @@ func getSingleData(kvStore store.Store, dataCh chan *StoredData, errCh chan erro
|
|||||||
close(dataCh)
|
close(dataCh)
|
||||||
close(errCh)
|
close(errCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b KVBackend) getStoredData(watch bool) (<-chan *StoredData, <-chan error) {
|
|
||||||
dataCh := make(chan *StoredData)
|
|
||||||
errCh := make(chan error)
|
|
||||||
|
|
||||||
backend, err := register(b.Name)
|
|
||||||
if err != nil {
|
|
||||||
go func() {
|
|
||||||
errCh <- err
|
|
||||||
}()
|
|
||||||
return dataCh, errCh
|
|
||||||
}
|
|
||||||
kvStore, err := valkeyrie.NewStore(
|
|
||||||
backend,
|
|
||||||
b.Client,
|
|
||||||
b.Config,
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
go func() {
|
|
||||||
errCh <- err
|
|
||||||
}()
|
|
||||||
return dataCh, errCh
|
|
||||||
}
|
|
||||||
|
|
||||||
if !watch {
|
|
||||||
go getSingleData(kvStore, dataCh, errCh)
|
|
||||||
return dataCh, errCh
|
|
||||||
}
|
|
||||||
|
|
||||||
go loopKV(watch, kvStore, dataCh, errCh)
|
|
||||||
|
|
||||||
return dataCh, errCh
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user