Update Staert.

This commit is contained in:
Ludovic Fernandez 2018-02-12 16:42:02 +01:00 committed by Traefiker Bot
parent 794c0206f3
commit 91fa727c74
3 changed files with 45 additions and 10 deletions

6
Gopkg.lock generated
View file

@ -243,8 +243,8 @@
[[projects]] [[projects]]
name = "github.com/containous/staert" name = "github.com/containous/staert"
packages = ["."] packages = ["."]
revision = "dbb7c840f31daec0d863ada6829d075a8dbb7469" revision = "cc00c303ccbd2491ddc1dccc9eb7ccadd807557e"
version = "v3.0.0" version = "v3.1.0"
[[projects]] [[projects]]
name = "github.com/containous/traefik-extra-service-fabric" name = "github.com/containous/traefik-extra-service-fabric"
@ -1496,6 +1496,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "865659187f3824cb57b8ff8805e3114b806c67ee0ffe9cbc6db237e4038edee6" inputs-digest = "17cefac15e170ca9d73093cad7a8f1fb6874cd03eeb67ccc3f8fe4d239f6e9aa"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -62,7 +62,7 @@
[[constraint]] [[constraint]]
name = "github.com/containous/staert" name = "github.com/containous/staert"
version = "3.0.0" version = "3.1.0"
[[constraint]] [[constraint]]
name = "github.com/containous/traefik-extra-service-fabric" name = "github.com/containous/traefik-extra-service-fabric"

View file

@ -1,10 +1,14 @@
package staert package staert
import ( import (
"bytes"
"compress/gzip"
"encoding" "encoding"
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil"
"reflect" "reflect"
"sort" "sort"
"strconv" "strconv"
@ -155,16 +159,32 @@ func decodeHook(fromType reflect.Type, toType reflect.Type, data interface{}) (i
return dataOutput, nil return dataOutput, nil
} else if fromType.Kind() == reflect.String { } else if fromType.Kind() == reflect.String {
b, err := base64.StdEncoding.DecodeString(data.(string)) return readCompressedData(data.(string), gzipReader, base64Reader)
if err != nil {
return nil, err
}
return b, nil
} }
} }
return data, nil 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 // StoreConfig stores the config into the KV Store
func (kv *KvSource) StoreConfig(config interface{}) error { func (kv *KvSource) StoreConfig(config interface{}) error {
kvMap := map[string]string{} kvMap := map[string]string{}
@ -263,7 +283,11 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string
case reflect.Array, reflect.Slice: case reflect.Array, reflect.Slice:
// Byte slices get special treatment // Byte slices get special treatment
if objValue.Type().Elem().Kind() == reflect.Uint8 { 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 { } else {
for i := 0; i < objValue.Len(); i++ { for i := 0; i < objValue.Len(); i++ {
name = key + "/" + strconv.Itoa(i) name = key + "/" + strconv.Itoa(i)
@ -286,6 +310,17 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string
return nil 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 // ListRecursive lists all key value children under key
func (kv *KvSource) ListRecursive(key string, pairs map[string][]byte) error { func (kv *KvSource) ListRecursive(key string, pairs map[string][]byte) error {
pairsN1, err := kv.List(key, nil) pairsN1, err := kv.List(key, nil)