Beispiel #1
0
// Json returns the map that marshals from the reply bytes as json in response .
func (r *Reply) Json(v interface{}) error {
	js, err := r.Bytes()
	if err != nil {
		return err
	}
	return utils.JsonDecode(js, v)
}
Beispiel #2
0
func LoadDataSetFromString(json string) (DataSet, error) {

	var ds DataSet

	err := utils.JsonDecode(json, &ds)

	return ds, err
}
Beispiel #3
0
// ReplyJson returns the map that marshals from the body bytes as json in response .
func (c *HttpClientRequest) ReplyJson(v interface{}) error {
	data, err := c.ReplyBytes()
	if err != nil {
		return err
	}
	err = utils.JsonDecode(data, v)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #4
0
func Initialize(prefix string) error {

	if prefix == "" {
		if p, err := filepath.Abs(os.Args[0]); err == nil {
			p, _ = path.Split(p)
			prefix, _ = filepath.Abs(p + "/..")
		}
	}

	reg, _ := regexp.Compile("/+")
	prefix = "/" + strings.Trim(reg.ReplaceAllString(prefix, "/"), "/")

	cfgfile := prefix + "/etc/config.json"
	if _, err := os.Stat(cfgfile); err != nil && os.IsNotExist(err) {
		return errors.New("Error: config cfgfile is not exists")
	}

	fp, err := os.Open(cfgfile)
	if err != nil {
		return errors.New(fmt.Sprintf("Error: Can not open (%s)", cfgfile))
	}
	defer fp.Close()

	cfgstr, err := ioutil.ReadAll(fp)
	if err != nil {
		return errors.New(fmt.Sprintf("Error: Can not read (%s)", cfgfile))
	}

	if err = utils.JsonDecode(cfgstr, &Config); err != nil {
		return errors.New(fmt.Sprintf("Error: "+
			"config file invalid. (%s)", err.Error()))
	}

	Config.Version = VERSION
	Config.Prefix = prefix

	idclient.ServiceUrl = Config.LessIdsUrl

	return nil
}
Beispiel #5
0
// Json returns the map that marshals from the reply bytes as json in response .
func (f *Field) Json(v interface{}) error {
	return utils.JsonDecode(f.String(), v)
}
Beispiel #6
0
func (r *Entry) Json(v interface{}) error {
	return utils.JsonDecode(r.Value, v)
}
Beispiel #7
0
// Json returns the map that marshals from the reply bytes as json in response .
func (r *Reply) Json(v interface{}) error {
	return utils.JsonDecode(r.String(), v)
}
Beispiel #8
0
// Json returns the map that marshals from the reply value string as json in response .
func (n *Node) Json(v interface{}) error {
	return utils.JsonDecode(n.Value, v)
}