human readable yaml
parent
44ce475100
commit
aef66625c0
|
|
@ -6,6 +6,8 @@ replace local/storage => ../
|
||||||
|
|
||||||
replace local/args => ../../args
|
replace local/args => ../../args
|
||||||
|
|
||||||
|
replace local/logb => ../../logb
|
||||||
|
|
||||||
require (
|
require (
|
||||||
local/args v0.0.0-00010101000000-000000000000
|
local/args v0.0.0-00010101000000-000000000000
|
||||||
local/storage v0.0.0-00010101000000-000000000000
|
local/storage v0.0.0-00010101000000-000000000000
|
||||||
|
|
|
||||||
24
yaml.go
24
yaml.go
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
@ -83,8 +85,11 @@ func (y *Yaml) GetStream(key string, ns ...string) (io.Reader, error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
b, err := base64.StdEncoding.DecodeString(s)
|
if strings.HasPrefix("b64://", s) {
|
||||||
return bytes.NewReader(b), err
|
b, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(s, "b64://"))
|
||||||
|
return bytes.NewReader(b), err
|
||||||
|
}
|
||||||
|
return strings.NewReader(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (y *Yaml) Set(key string, value []byte, ns ...string) error {
|
func (y *Yaml) Set(key string, value []byte, ns ...string) error {
|
||||||
|
|
@ -99,6 +104,15 @@ func (y *Yaml) Del(key string, ns ...string) error {
|
||||||
return y.SetStream(key, nil, ns...)
|
return y.SetStream(key, nil, ns...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isASCII(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
if c > unicode.MaxASCII {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (y *Yaml) SetStream(key string, r io.Reader, ns ...string) error {
|
func (y *Yaml) SetStream(key string, r io.Reader, ns ...string) error {
|
||||||
namespace := resolve.Namespace(ns)
|
namespace := resolve.Namespace(ns)
|
||||||
var v interface{} = nil
|
var v interface{} = nil
|
||||||
|
|
@ -107,7 +121,11 @@ func (y *Yaml) SetStream(key string, r io.Reader, ns ...string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v = base64.StdEncoding.EncodeToString(b)
|
if isASCII(string(b)) {
|
||||||
|
v = string(b)
|
||||||
|
} else {
|
||||||
|
v = "b64://" + base64.StdEncoding.EncodeToString(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m, err := y.getMap()
|
m, err := y.getMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue