抛出异常

This commit is contained in:
liangzy 2020-04-03 11:21:51 +08:00
parent 1869fc6de7
commit b88d45686a
4 changed files with 11 additions and 31 deletions

1
conf/dev/test.yaml Normal file
View File

@ -0,0 +1 @@
Aa: "hello world"

1
conf/test.yaml Normal file
View File

@ -0,0 +1 @@
Aa: "hello world"

View File

@ -1,38 +1,12 @@
package grconfig
import (
"fmt"
"log"
"lot.gaore.com/library/common"
"lot.gaore.com/library/grconfig"
"testing"
)
type Config struct {
ServerUrl string `yaml:"server_url"`
AccessKey string `yaml:"access_key"`
SecretKey string `yaml:"secret_key"`
InstanceId string `yaml:"instance_id"`
}
func TestNewConfig(t *testing.T) {
var m1 Config
var m2 Config
c := New(common.GetCwd("conf"))
err := c.Item("mqtt.default", &m1)
log.Println(fmt.Sprintf("%+v", m1.ServerUrl))
if err != nil {
t.Error(err)
}
err = c.Item("mqtt.backup", &m2)
log.Println(fmt.Sprintf("%+v", m2.ServerUrl))
if err != nil {
t.Error(err)
}
if c.String("mqtt.default.instance_id") == "" {
t.Error("Empty String")
}
log.Println(c.String("mqtt.default.instance_id"))
func TestNew(t *testing.T) {
gr := grconfig.New("conf/")
log.Println(gr.String("test.a"))
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"gopkg.in/yaml.v2"
"log"
"strings"
)
@ -36,6 +37,9 @@ func (conf *ConfigerChannelYAML) Item(item string, t interface{}) (err error) {
func parseYAML(buf bytes.Buffer) interface{} {
var v interface{}
yaml.Unmarshal(buf.Bytes(), &v)
if err := yaml.Unmarshal(buf.Bytes(), &v); err != nil {
log.Println(err)
panic(err)
}
return v
}