fix errors & improve code quality
This commit is contained in:
parent
a8a5a10410
commit
a4951096c1
10
file.go
10
file.go
@ -58,17 +58,17 @@ func (b FileBackend) loop(watch bool) (<-chan *StoredData, <-chan error) {
|
||||
return
|
||||
}
|
||||
if event.Op&fsnotify.Write == fsnotify.Write {
|
||||
data, err := getStoredDataFromFile(b.Path)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
data, err1 := getStoredDataFromFile(b.Path)
|
||||
if err1 != nil {
|
||||
errCh <- err1
|
||||
}
|
||||
dataCh <- data
|
||||
}
|
||||
case err, ok := <-watcher.Errors:
|
||||
case err1, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
errCh <- err
|
||||
errCh <- err1
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
15
kv.go
15
kv.go
@ -23,7 +23,6 @@ func getStoredDataFromGzip(value []byte) (*StoredData, error) {
|
||||
data := &StoredData{}
|
||||
|
||||
r, err := gzip.NewReader(bytes.NewBuffer(value))
|
||||
defer r.Close()
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
@ -63,7 +62,7 @@ func register(backend string) (store.Backend, error) {
|
||||
boltdb.Register()
|
||||
return store.BOLTDB, nil
|
||||
default:
|
||||
return "", fmt.Errorf("No backend found for %v", backend)
|
||||
return "", fmt.Errorf("no backend found for %v", backend)
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,14 +89,12 @@ func (b KVBackend) loop(watch bool) (<-chan *StoredData, <-chan error) {
|
||||
stopCh := make(<-chan struct{})
|
||||
events, _ := kvstore.Watch(storeKey, stopCh, nil)
|
||||
for {
|
||||
select {
|
||||
case kvpair := <-events:
|
||||
storedData, err := getStoredDataFromGzip(kvpair.Value)
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
dataCh <- storedData
|
||||
kvpair := <-events
|
||||
storedData, err := getStoredDataFromGzip(kvpair.Value)
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
dataCh <- storedData
|
||||
if !watch {
|
||||
close(dataCh)
|
||||
close(errors)
|
||||
|
||||
6
main.go
6
main.go
@ -25,10 +25,10 @@ func main() {
|
||||
Long: `Dump the content of the "acme.json" file from Traefik to certificates.`,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
source := cmd.Flag("source").Value.String()
|
||||
sourceFile := cmd.Flag("source-file").Value.String()
|
||||
sourceFile := cmd.Flag("file").Value.String()
|
||||
if source == "file" {
|
||||
if _, err := os.Stat(sourceFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf("--source-file (%q) does not exist", sourceFile)
|
||||
return fmt.Errorf("--file (%q) does not exist", sourceFile)
|
||||
}
|
||||
} else if source != "consul" && source != "etcd" && source != "zookeeper" && source != "boltdb" {
|
||||
return fmt.Errorf("--source (%q) is not allowed, use one of 'file', 'consul', 'etcd', 'zookeeper', 'boltdb'", source)
|
||||
@ -49,7 +49,7 @@ func main() {
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
|
||||
source := cmd.Flag("source").Value.String()
|
||||
acmeFile := cmd.Flag("source-file").Value.String()
|
||||
acmeFile := cmd.Flag("file").Value.String()
|
||||
|
||||
switch source {
|
||||
case "file":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user