当前位置: 首页>>代码示例>>Golang>>正文


Golang Container.Path方法代码示例

本文整理汇总了Golang中github.com/jeffail/gabs.Container.Path方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.Path方法的具体用法?Golang Container.Path怎么用?Golang Container.Path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jeffail/gabs.Container的用法示例。


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

示例1: scrapeMeter

func (e *Exporter) scrapeMeter(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no count\n", key))
	}
	units, ok := json.Path("units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(meterHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	gauge, _ := e.Gauges.Fetch(name, help, "rate")
	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		if strings.Contains(key, "rate") {
			if value, ok := property.Data().(float64); ok {
				gauge.WithLabelValues(renameRate(key)).Set(value)
			}
		}
	}

	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:27,代码来源:exporter.go

示例2: scrapeTimer

func (e *Exporter) scrapeTimer(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no count\n", key))
	}
	units, ok := json.Path("rate_units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(timerHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	rates, _ := e.Gauges.Fetch(name+"_rate", help, "rate")
	percentiles, _ := e.Gauges.Fetch(name, help, "percentile")
	min, _ := e.Gauges.Fetch(name+"_min", help)
	max, _ := e.Gauges.Fetch(name+"_max", help)
	mean, _ := e.Gauges.Fetch(name+"_mean", help)
	stddev, _ := e.Gauges.Fetch(name+"_stddev", help)

	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		switch key {
		case "mean_rate", "m1_rate", "m5_rate", "m15_rate":
			if value, ok := property.Data().(float64); ok {
				rates.WithLabelValues(renameRate(key)).Set(value)
			}

		case "p50", "p75", "p95", "p98", "p99", "p999":
			if value, ok := property.Data().(float64); ok {
				percentiles.WithLabelValues("0." + key[1:]).Set(value)
			}
		case "min":
			if value, ok := property.Data().(float64); ok {
				min.WithLabelValues().Set(value)
			}
		case "max":
			if value, ok := property.Data().(float64); ok {
				max.WithLabelValues().Set(value)
			}
		case "mean":
			if value, ok := property.Data().(float64); ok {
				mean.WithLabelValues().Set(value)
			}
		case "stddev":
			if value, ok := property.Data().(float64); ok {
				stddev.WithLabelValues().Set(value)
			}
		}
	}

	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:55,代码来源:exporter.go

示例3: scrapeGauge

func (e *Exporter) scrapeGauge(key string, json *gabs.Container) (bool, error) {
	data := json.Path("value").Data()
	value, ok := data.(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for gauge %s\n", data, key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(gaugeHelp, key)
	gauge, new := e.Gauges.Fetch(name, help)
	gauge.WithLabelValues().Set(value)
	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:13,代码来源:exporter.go

示例4: scrapeCounter

func (e *Exporter) scrapeCounter(key string, json *gabs.Container) (bool, error) {
	data := json.Path("count").Data()
	count, ok := data.(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for counter %s\n", data, key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(counterHelp, key)
	counter, new := e.Counters.Fetch(name, help)
	counter.WithLabelValues().Set(count)
	return new, nil
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:13,代码来源:exporter.go

示例5: ExtractAndCheckToken

func (svc *Service) ExtractAndCheckToken(so socketio.Socket, g *gabs.Container) (string, bool) {
	if g.Path("t").Data() == nil {
		so.Emit("auth_error", "Missing Token")
		return "", false
	}

	uid, err := svc.ValidateUserToken(nil, g.Path("t").Data().(string))
	if err != nil {
		so.Emit("auth_error", "Invalid Token")
		return "", false
	}

	return uid, true
}
开发者ID:timbwhitt,项目名称:assemble-web-chat,代码行数:14,代码来源:service.go

示例6: documentFromHit

func documentFromHit(hit *gabs.Container) *Document {
	return &Document{
		Index:  hit.Path("_index").Data().(string),
		Type:   hit.Path("_type").Data().(string),
		Id:     hit.Path("_id").Data().(string),
		source: []byte(hit.Path("_source").String()),
	}
}
开发者ID:josue,项目名称:esdump,代码行数:8,代码来源:dumper.go

示例7: signupHandler

// signupHandler controls the signup and user profile update forms
func signupHandler(w http.ResponseWriter, r *http.Request) {
	if strings.ToUpper(r.Method) == "POST" {
		invite, ok := service.Invites[r.FormValue("invite")]
		tokenenc := r.FormValue("token")

		var token *gabs.Container

		if ok {
			delete(service.Invites, r.FormValue("invite"))
			token, _ = assemble.CreateNewUserToken(
				r.FormValue("nick"),
				r.FormValue("name"),
				r.FormValue("email"),
				r.FormValue("phone"),
				r.FormValue("url"),
				r.FormValue("desc"),
				r.FormValue("avatar"),
				r.FormValue("alertaddress"))
		} else if tokenenc != "" {
			uid, tokerr := service.ValidateUserToken(nil, tokenenc)
			if tokerr == nil {
				privid := service.Users[uid].Token.Path("privid").Data().(string)
				token, _ = assemble.CreateUpdatedUserToken(
					r.FormValue("nick"),
					r.FormValue("name"),
					r.FormValue("email"),
					r.FormValue("phone"),
					r.FormValue("url"),
					r.FormValue("desc"),
					r.FormValue("avatar"),
					r.FormValue("alertaddress"),
					uid, privid)

				log.Println(uid, "updated user token")
			} else {
				tokenenc = ""
			}
		}

		if ok || tokenenc != "" {

			competok := utils.Compress([]byte(token.String()))
			etok, _ := utils.Encrypt(service.UserKey, competok.Bytes())

			service.AddToRoom(nil, token.Path("uid").Data().(string), "lobby")

			//TODO use templates
			fmt.Fprintf(w, `<html>`)
			fmt.Fprintf(w, `<meta http-equiv="refresh" content="10; url=/#%s">`, base64.StdEncoding.EncodeToString(etok))
			if ok {
				fmt.Fprintf(w, `<strong>SUCCESS!</strong> `+invite+`<br><br>`)
			} else {
				fmt.Fprintf(w, `<strong>Delete your old login bookmark and close the window or you will still be using your old profile!</strong><br><br>`)
			}
			//fmt.Fprintf(w, "Token (KEEP THIS SOMEWHERE SAFE OR SAVE THE LOGIN LINK): <br><textarea rows='10' cols='60'>%s</textarea><br><br>", base64.StdEncoding.EncodeToString(etok))
			fmt.Fprintf(w, "<a href='/#%s' target='_blank'>Assemble Chat Login - CLICK HERE AND BOOKMARK THE CHAT!</a> <strong>DO NOT SHARE THIS LINK</strong>", base64.StdEncoding.EncodeToString(etok))
			fmt.Fprintf(w, "<br>You will automatically enter the chat in 10 seconds...")
			fmt.Fprintf(w, `</html>`)
		} else {
			fmt.Fprintf(w, `Invalid Invite ID or Token`)
		}
	} else {
		fc, _ := ioutil.ReadFile("./static/signup.html")
		if fc != nil {
			fmt.Fprintf(w, string(fc[:]))
		}
	}
}
开发者ID:pageben,项目名称:assemble-web-chat,代码行数:69,代码来源:assemble.go

示例8: cleanToken

func cleanToken(token *gabs.Container) {
	token.SetP(html.EscapeString(token.Path("nick").Data().(string)), "nick")
	token.SetP(html.EscapeString(token.Path("uid").Data().(string)), "uid")
	token.SetP(html.EscapeString(token.Path("name").Data().(string)), "name")
	token.SetP(html.EscapeString(token.Path("email").Data().(string)), "email")
	token.SetP(html.EscapeString(token.Path("phone").Data().(string)), "phone")
	token.SetP(html.EscapeString(token.Path("url").Data().(string)), "url")
	token.SetP(html.EscapeString(token.Path("desc").Data().(string)), "desc")
	token.SetP(html.EscapeString(token.Path("avatar").Data().(string)), "avatar")
}
开发者ID:timbwhitt,项目名称:assemble-web-chat,代码行数:10,代码来源:service.go


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