コード例 #1
0
ファイル: reply.go プロジェクト: ego008/lessgo
// 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)
}
コード例 #2
0
ファイル: schema.go プロジェクト: ego008/lessgo
func LoadDataSetFromString(json string) (DataSet, error) {

	var ds DataSet

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

	return ds, err
}
コード例 #3
0
ファイル: httpclient.go プロジェクト: ego008/lessgo
// 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
}
コード例 #4
0
ファイル: config.go プロジェクト: lessos/lesscreator
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
}
コード例 #5
0
ファイル: field.go プロジェクト: ego008/lessgo
// 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)
}
コード例 #6
0
ファイル: reply.go プロジェクト: ego008/lessgo
func (r *Entry) Json(v interface{}) error {
	return utils.JsonDecode(r.Value, v)
}
コード例 #7
0
ファイル: reply.go プロジェクト: ego008/lessgo
// 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)
}
コード例 #8
0
ファイル: lesskeeper.go プロジェクト: ego008/lessgo
// 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)
}