• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang go-simplejson.Json类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bitly/go-simplejson.Json的典型用法代码示例。如果您正苦于以下问题:Golang Json类的具体用法?Golang Json怎么用?Golang Json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Json类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: parseResult

func parseResult(data *json.Json) (string, bool) {
	address, ok := data.CheckGet("display_name")
	if ok {
		return address.MustString(), true
	}
	return "", false
}
开发者ID:xmjw,项目名称:locator,代码行数:7,代码来源:reverse_geocode.go


示例2: getSubnet

func getSubnet(r *http.Request) (*SapiProvisionedSubnets, error) {
	var port *sjson.Json
	var sapiSubnet = &SapiProvisionedSubnets{}

	post, err := sjson.NewFromReader(r.Body)
	if err != nil {
		return nil, err
	}

	port, ok := post.CheckGet("subnet")
	if !ok {
		return nil, ErrorNoPort
	}

	b, err := port.Encode()
	if err != nil {
		return nil, err
	}
	if err = json.Unmarshal(b, sapiSubnet); err != nil {
		return nil, err
	}
	if err != nil {
		return nil, err
	}

	return sapiSubnet, nil
}
开发者ID:wangtaoX,项目名称:sapi-go,代码行数:27,代码来源:subnet.go


示例3: syncPort

func syncPort(data *sjson.Json) (err error) {
	var sapiPorts []*SapiProvisionedPorts
	var fixips []*struct {
		Ips []map[string]string `json:"fixed_ips"`
	}

	port, ok := data.CheckGet("port")
	if !ok {
		return ErrorNoNet
	}
	bytes, err := port.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiPorts); err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &fixips); err != nil {
		return err
	}

	new(SapiProvisionedPorts).truncate()
	for index, port := range sapiPorts {
		//fmt.Println(index, *port, fixips[index].Ips[0]["ip_address"], fixips[index].Ips[0]["subnet_id"])
		if len(fixips[index].Ips) >= 1 {
			port.IpAddress = fixips[index].Ips[0]["ip_address"]
			port.SubnetId = fixips[index].Ips[0]["subnet_id"]
		}
		if err := port.insert(); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:wangtaoX,项目名称:sapi-go,代码行数:35,代码来源:sync.go


示例4: buildMongoWhereByArray

func buildMongoWhereByArray(wheres *simplejson.Json, primaryKey string) []bson.M {
	mongoWheres := []bson.M{}
	for key, _ := range wheres.MustArray() {
		mongoWhere := BuildMongoWhere(wheres.GetIndex(key), primaryKey)
		mongoWheres = append(mongoWheres, mongoWhere)
	}
	return mongoWheres
}
开发者ID:andreaugusto,项目名称:beat,代码行数:8,代码来源:mongo.go


示例5: Message

func (this *Context) Message(data *simplejson.Json) {
	content, err := data.Get("content").String()
	if err != nil {
		log.Println(err)
		return
	}

	gContexts.SendAll(map[string]interface{}{
		"type":     "message",
		"userName": this.UserName,
		"content":  content,
	})
}
开发者ID:whcrow,项目名称:go-chatroom,代码行数:13,代码来源:message.go


示例6: Initialize

func Initialize(json *simpleJson.Json) *SlackBot {
	if slackBot != nil {
		return slackBot
	}

	self := json.Get("self")

	slackBot = &SlackBot{
		Id:   self.Get("id").MustString(),
		Name: self.Get("name").MustString(),
	}
	return slackBot
}
开发者ID:hirakiuc,项目名称:gonta,代码行数:13,代码来源:bot.go


示例7: Init

func (p *NsqSrcProvider) Init(ctx *sj.Json) error {
	var err error
	p.nsqMsgChan = make(chan nsq.Message) // not buffered

	p.timeOutSec = ctx.Get("timeout_sec").MustInt()
	nsqLookupdAddrs := ctx.Get("nsq_lookupd_addrs").MustStringArray()
	if len(nsqLookupdAddrs) <= 0 {
		return errors.New("no nsq_lookupd_addr in provided")
	}
	topic := ctx.Get("topic").MustString()
	channel := ctx.Get("channel").MustString()

	p.config = nsq.NewConfig()
	p.consumer, err = nsq.NewConsumer(topic, channel, p.config)
	if p.consumer == nil || err != nil {
		return err
	}

	p.consumer.AddHandler(nsq.HandlerFunc(func(message *nsq.Message) error {
		p.nsqMsgChan <- *message
		return nil
	}))

	err = p.consumer.ConnectToNSQLookupds(nsqLookupdAddrs) // ip:port
	if err != nil {
		return errors.New("Could not connect to nsqLookupd")
	}

	return nil
}
开发者ID:last-time,项目名称:della,代码行数:30,代码来源:nsq_src_provider.go


示例8: sumJSON

// Handles returning a sum for a *Json.
func sumJSON(json *simplejson.Json, ignoreRed bool) int {
	slice, err := json.Array()
	if err != nil {
		panic(err)
	}
	return sumSlice(slice, ignoreRed)
}
开发者ID:dhedegaard,项目名称:adventofcode,代码行数:8,代码来源:day12.go


示例9: Auth

func (this *Context) Auth(data *simplejson.Json) {
	userName, err := data.Get("userName").String()
	if err != nil {
		log.Println(err)
		return
	}
	this.UserName = userName

	// send message
	userNames := gContexts.GetAllUserNames()
	gContexts.SendAll(map[string]interface{}{
		"type":      "auth",
		"message":   userName + "进入聊天室",
		"userNames": userNames,
	})
}
开发者ID:whcrow,项目名称:go-chatroom,代码行数:16,代码来源:message.go


示例10: BuildMongoWhere

func BuildMongoWhere(where *simplejson.Json, primaryKey string) bson.M {
	mongoWhere := bson.M{}
	for key, value := range where.MustMap() {
		switch key {
		case "and", "or", "nor":
			mongoWhere["$"+key] = buildMongoWhereByArray(
				where.Get(key),
				primaryKey,
			)
			continue

		case primaryKey:
			mongoWhere["_id"] = value
			continue
		}
		mongoWhere[key] = value
	}
	return mongoWhere
}
开发者ID:andreaugusto,项目名称:beat,代码行数:19,代码来源:mongo.go


示例11: Init

func (p *DmSrcProvider) Init(ctx *sj.Json) error {
	var err error

	p.monitorIntervalSec = ctx.Get("monitor_interval_sec").MustInt(10)
	p.popLastFile = ctx.Get("pop_last_file").MustBool(true)
	p.timeOutMs = ctx.Get("time_out_ms").MustInt(10000)
	p.dataDir = ctx.Get("data_dir").MustString("/tmp")
	stat, err := os.Stat(p.dataDir)
	if (err != nil && !os.IsExist(err)) || !stat.IsDir() {
		return errors.New("data dir not valid")
	}

	p.lastFileMap = make(map[string]string)
	paths := ctx.Get("monitor_paths").MustStringArray()
	if len(paths) <= 0 {
		return errors.New("no monitor_paths is provided")
	}
	if err = p.initMonitorPaths(paths); err != nil {
		return err
	}
	return nil
}
开发者ID:last-time,项目名称:della,代码行数:22,代码来源:dm_src_provider.go


示例12: syncNet

func syncNet(data *sjson.Json) (err error) {
	var sapiNets []*SapiProvisionedNets

	network, ok := data.CheckGet("network")
	if !ok {
		return ErrorNoNet
	}
	bytes, err := network.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiNets); err != nil {
		return err
	}

	new(SapiProvisionedNets).truncate()
	for _, net := range sapiNets {
		if err := net.insert(); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:wangtaoX,项目名称:sapi-go,代码行数:23,代码来源:sync.go


示例13: syncSubnet

func syncSubnet(data *sjson.Json) (err error) {
	var sapiSubnets []*SapiProvisionedSubnets

	subnet, ok := data.CheckGet("subnet")
	if !ok {
		return ErrorNoSubnet
	}
	bytes, err := subnet.Encode()
	if err != nil {
		return err
	}
	if err = json.Unmarshal(bytes, &sapiSubnets); err != nil {
		return err
	}

	new(SapiProvisionedSubnets).truncate()
	for _, subnet := range sapiSubnets {
		if err := subnet.insert(); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:wangtaoX,项目名称:sapi-go,代码行数:23,代码来源:sync.go


示例14: getNet

func getNet(r *http.Request) (*SapiProvisionedNets, error) {
	var network *sjson.Json
	var sapiNet = &SapiProvisionedNets{}

	post, err := sjson.NewFromReader(r.Body)
	if err != nil {
		return nil, err
	}
	network, ok := post.CheckGet("network")
	if !ok {
		return nil, ErrorNoNet
	}
	b, err := network.Encode()
	if err != nil {
		return nil, err
	}

	if err = json.Unmarshal(b, sapiNet); err != nil {
		return nil, err
	}

	return sapiNet, nil
}
开发者ID:wangtaoX,项目名称:sapi-go,代码行数:23,代码来源:network.go


示例15: Init

func (p *Workshop) Init(ctx *sj.Json, upCtrlChan chan int, upReportChan chan int, isTest bool) error {
	p.ctx = ctx
	p.upCtrlChan = upCtrlChan
	p.upReportChan = upReportChan

	p.processedLine = 0
	var err error
	if err = p.initLog(isTest); err != nil {
		return err
	}
	logger.Debug("workshop init log success")

	if err = p.initSrcProvider(); err != nil {
		return err
	}
	logger.Debug("workshop init srcProvider success")

	p.cronTickInterval = ctx.Get("main").Get("cron_tick_interval").MustInt()
	p.memLimit = ctx.Get("main").Get("mem_limit").MustUint64()
	p.PRCtrlChan = make(chan int, 1000) // 1000 is enough
	p.PRReportChan = make(chan int)
	p.CLCtrlChan = make(chan int, 1000) // 1000 is enough
	p.CLReportChan = make(chan int)

	if err = p.initChannel(isTest); err != nil {
		return err
	}
	logger.Debug("workshop init channel and subroutine success")

	logger.Info("start...  config:\n[", *p.ctx, "]\n")
	if isTest {
		p.provider.Destory()
	}
	logger.SetConsole(false)
	return nil
}
开发者ID:last-time,项目名称:della,代码行数:36,代码来源:workshop.go


示例16: parseCreateJobBody

func parseCreateJobBody(js *simplejs.Json) (string, map[string]string) {
	m := make(map[string]string)
	jobname, err := js.Get("jobname").String()
	if err != nil {
		log.Errorf("parse \"jobname\" failed")
		return "", nil
	}
	/*
		else {
			m["jobname"] = jobname
			fmt.Println(jobname)
		}*/
	if desc, err := js.Get("description").String(); err != nil {
		log.Errorf("parse \"description\" failed")
		return "", nil
	} else {
		m["desc"] = desc
	}

	if repositryrUrl, err := js.Get("repositryurl").String(); err != nil {
		//log.Errorf("parse \"repositryurl\" failed")
		log.Errorf(err.Error())
		return "", nil
	} else {
		m["repositryurl"] = repositryrUrl
	}
	/*
		if credentialsId, err := js.Get("credentialsid").String(); err != nil {
			log.Errorf("parse \"credentialsid\" failed")
			return nil
		} else {
			m["credentialsid"] = credentialsId
		}
	*/
	if usr, err := js.Get("username").String(); err != nil {
		log.Errorf("parse \"username\" failed")
		return "", nil
	} else {
		m["username"] = usr
	}

	if passwd, err := js.Get("password").String(); err != nil {
		log.Errorf("parse \"password\" failed")
		return "", nil
	} else {
		m["password"] = passwd
	}

	if branchesToBuild, err := js.Get("branches").String(); err != nil {
		log.Errorf("parse \"branches\" failed")
		return "", nil
	} else {
		m["branchestobuild"] = branchesToBuild
	}
	/*
		// builders
		bdrs := js.Get("builders").Get("dockerbuildandpublish")
		if bdrs == nil {
			log.Errorf("parse \"dockerbuildandpublish\" failed")
			return nil
		}
	*/
	if repoName, err := js.Get("repositryname").String(); err != nil {
		log.Errorf("parse \"repositryname\" failed")
		return "", nil
	} else {
		m["repositryname"] = repoName
	}

	if tag, err := js.Get("tag").String(); err != nil {
		log.Errorf("parse \"tag\" failed")
		return "", nil
	} else {
		m["tag"] = tag
	}

	if dockerRegistryUrl, err := js.Get("dockerregistryurl").String(); err != nil {
		log.Errorf("parse \"dockerregistryurl\" failed")
		return "", nil
	} else {
		m["dockerregistryurl"] = dockerRegistryUrl
	}

	if dockerHostUri, err := js.Get("dockerhosturi").String(); err != nil {
		log.Errorf("parse \"dockerhosturi\" failed")
		return "", nil
	} else {
		m["dockerhosturi"] = dockerHostUri
	}

	if skipPush, err := js.Get("skippush").String(); err != nil {
		log.Errorf("parse \"skippush\" failed")
		return "", nil
	} else {
		m["skippush"] = skipPush
	}

	if cmd, err := js.Get("command").String(); err != nil {
		log.Errorf("parse \"command\" failed")
		return "", nil
//.........这里部分代码省略.........
开发者ID:zhanglianx111,项目名称:lasa,代码行数:101,代码来源:jobs.go


示例17: createTableStatement

func createTableStatement(tableName *string, columnsJson *simplejson.Json, uniqueColumns *simplejson.Json, primaryKeyColumns *simplejson.Json) string {
	var buffer bytes.Buffer
	buffer.WriteString("CREATE TABLE ")
	buffer.WriteString(*tableName)
	buffer.WriteString(" (\n")

	columnsArry, err := columnsJson.Array()
	if err != nil {
		reportError("Couldn't parse columns json: ", err)
	}
	for i, _ := range columnsArry {
		if i != 0 {
			buffer.WriteString(",\n")
		}
		columnSchema := columnsJson.GetIndex(i)
		columnName, err := columnSchema.Get("name").String()
		if err != nil {
			reportError("Couldn't parse column name for table json: ", err)
		}
		columnType, err := columnSchema.Get("type").String()
		if err != nil {
			reportError("Couldn't parse column type for table json: ", err)
		}
		buffer.WriteString(columnName)
		buffer.WriteString(" ")
		buffer.WriteString(columnType)

		if columnUnique, err := columnSchema.Get("unique").Bool(); err == nil && columnUnique {
			buffer.WriteString(" UNIQUE")
		}

		if columnNull, err := columnSchema.Get("null").Bool(); err == nil && !columnNull {
			buffer.WriteString(" NOT NULL")
		}
	}

	uniqueColumnsArry, err := uniqueColumns.Array()
	if err == nil && len(uniqueColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
		buffer.WriteString(",\nUNIQUE (")
		for i, _ := range uniqueColumnsArry {
			if i != 0 {
				buffer.WriteString(", ")
			}
			uniqueColumnName, err := uniqueColumns.GetIndex(i).String()
			if err != nil {
				reportError("Couldn't parse unique column name for table json: ", err)
			}
			buffer.WriteString(uniqueColumnName)
		}
		buffer.WriteString(")")
	}

	primaryKeyColumnsArry, err := primaryKeyColumns.Array()
	if err == nil && len(primaryKeyColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
		buffer.WriteString(",\nUNIQUE (")
		for i, _ := range primaryKeyColumnsArry {
			if i != 0 {
				buffer.WriteString(", ")
			}
			primaryKeyColumnName, err := primaryKeyColumns.GetIndex(i).String()
			if err != nil {
				reportError("Couldn't parse primary key column name for table json: ", err)
			}
			buffer.WriteString(primaryKeyColumnName)
		}
		buffer.WriteString(")")
	}

	buffer.WriteString("\n);")

	return buffer.String()
}
开发者ID:gawkermedia,项目名称:redshift-tracking-copy-from-s3,代码行数:72,代码来源:main.go


示例18: Init

func (p *PrintProcessor) Init(ctx *sj.Json, id int, itemChans [](chan Item)) error {
	p.id = id
	p.itemChans = itemChans
	p.category = ctx.Get("category").MustString("print")
	return nil
}
开发者ID:last-time,项目名称:della,代码行数:6,代码来源:print_processor.go



注:本文中的github.com/bitly/go-simplejson.Json类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang app.Logger类代码示例发布时间:2022-05-24
下一篇:
Golang go-simplejson.NewJson函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap