當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Json.Get方法代碼示例

本文整理匯總了Golang中github.com/bitly/go-simplejson.Json.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Json.Get方法的具體用法?Golang Json.Get怎麽用?Golang Json.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/bitly/go-simplejson.Json的用法示例。


在下文中一共展示了Json.Get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parseResult

func parseResult(data *json.Json) (string, bool) {
	for i, _ := range data.Get("results").MustArray() {
		item := data.Get("results").GetIndex(i)
		address, ok := item.CheckGet("formatted_address")
		if ok {
			return address.MustString(), true
		}
	}
	return "", false
}
開發者ID:xmjw,項目名稱:locator,代碼行數:10,代碼來源:reverse_geocode.go

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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


注:本文中的github.com/bitly/go-simplejson.Json.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。