Update Staert.
This commit is contained in:
parent
794c0206f3
commit
91fa727c74
3 changed files with 45 additions and 10 deletions
6
Gopkg.lock
generated
6
Gopkg.lock
generated
|
@ -243,8 +243,8 @@
|
|||
[[projects]]
|
||||
name = "github.com/containous/staert"
|
||||
packages = ["."]
|
||||
revision = "dbb7c840f31daec0d863ada6829d075a8dbb7469"
|
||||
version = "v3.0.0"
|
||||
revision = "cc00c303ccbd2491ddc1dccc9eb7ccadd807557e"
|
||||
version = "v3.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/containous/traefik-extra-service-fabric"
|
||||
|
@ -1496,6 +1496,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "865659187f3824cb57b8ff8805e3114b806c67ee0ffe9cbc6db237e4038edee6"
|
||||
inputs-digest = "17cefac15e170ca9d73093cad7a8f1fb6874cd03eeb67ccc3f8fe4d239f6e9aa"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
[[constraint]]
|
||||
name = "github.com/containous/staert"
|
||||
version = "3.0.0"
|
||||
version = "3.1.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/containous/traefik-extra-service-fabric"
|
||||
|
|
47
vendor/github.com/containous/staert/kv.go
generated
vendored
47
vendor/github.com/containous/staert/kv.go
generated
vendored
|
@ -1,10 +1,14 @@
|
|||
package staert
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -155,16 +159,32 @@ func decodeHook(fromType reflect.Type, toType reflect.Type, data interface{}) (i
|
|||
|
||||
return dataOutput, nil
|
||||
} else if fromType.Kind() == reflect.String {
|
||||
b, err := base64.StdEncoding.DecodeString(data.(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
return readCompressedData(data.(string), gzipReader, base64Reader)
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func readCompressedData(data string, fs ...func(io.Reader) (io.Reader, error)) ([]byte, error) {
|
||||
var err error
|
||||
for _, f := range fs {
|
||||
var reader io.Reader
|
||||
reader, err = f(bytes.NewBufferString(data))
|
||||
if err == nil {
|
||||
return ioutil.ReadAll(reader)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func base64Reader(r io.Reader) (io.Reader, error) {
|
||||
return base64.NewDecoder(base64.StdEncoding, r), nil
|
||||
}
|
||||
|
||||
func gzipReader(r io.Reader) (io.Reader, error) {
|
||||
return gzip.NewReader(r)
|
||||
}
|
||||
|
||||
// StoreConfig stores the config into the KV Store
|
||||
func (kv *KvSource) StoreConfig(config interface{}) error {
|
||||
kvMap := map[string]string{}
|
||||
|
@ -263,7 +283,11 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string
|
|||
case reflect.Array, reflect.Slice:
|
||||
// Byte slices get special treatment
|
||||
if objValue.Type().Elem().Kind() == reflect.Uint8 {
|
||||
kv[name] = base64.StdEncoding.EncodeToString(objValue.Bytes())
|
||||
compressedData, err := writeCompressedData(objValue.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kv[name] = compressedData
|
||||
} else {
|
||||
for i := 0; i < objValue.Len(); i++ {
|
||||
name = key + "/" + strconv.Itoa(i)
|
||||
|
@ -286,6 +310,17 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string
|
|||
return nil
|
||||
}
|
||||
|
||||
func writeCompressedData(data []byte) (string, error) {
|
||||
var buffer bytes.Buffer
|
||||
gzipWriter := gzip.NewWriter(&buffer)
|
||||
_, err := gzipWriter.Write(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
gzipWriter.Close()
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
// ListRecursive lists all key value children under key
|
||||
func (kv *KvSource) ListRecursive(key string, pairs map[string][]byte) error {
|
||||
pairsN1, err := kv.List(key, nil)
|
||||
|
|
Loading…
Reference in a new issue