本文整理汇总了Golang中github.com/jeffail/gabs.Container类的典型用法代码示例。如果您正苦于以下问题:Golang Container类的具体用法?Golang Container怎么用?Golang Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: scrapeMetrics
func (e *Exporter) scrapeMetrics(json *gabs.Container, ch chan<- prometheus.Metric) {
elements, _ := json.ChildrenMap()
for key, element := range elements {
switch key {
case "message":
log.Errorf("Problem collecting metrics: %s\n", element.Data().(string))
return
case "version":
data := element.Data()
version, ok := data.(string)
if !ok {
log.Errorf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for version\n", data))
} else {
gauge, _ := e.Gauges.Fetch("metrics_version", "Marathon metrics version", "version")
gauge.WithLabelValues(version).Set(1)
gauge.Collect(ch)
}
case "counters":
e.scrapeCounters(element)
case "gauges":
e.scrapeGauges(element)
case "histograms":
e.scrapeHistograms(element)
case "meters":
e.scrapeMeters(element)
case "timers":
e.scrapeTimers(element)
}
}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:31,代码来源:exporter.go
示例2: testGetMultStatementOfGroup
func testGetMultStatementOfGroup(t *testing.T, group *gabs.Container) {
db := initDatabase(t)
defer db.Close()
mart := initHandler(db)
ids := []string{
uuid.NewV4().String(),
uuid.NewV4().String(),
uuid.NewV4().String(),
uuid.NewV4().String(),
}
stmt, err := gabs.ParseJSON([]byte(statetmentAgentBoilerplate))
fatalIfError(t, err)
stmtSlice := []*gabs.Container{
appendAccount(t, stmt),
appendMbox(t, stmt),
appendMboxSHA1(t, stmt),
appendOpenID(t, stmt),
}
for i := 0; i < len(ids); i++ {
putStatement(t, mart, stmtSlice[i].String(), ids[i])
var s interface{}
err = json.Unmarshal([]byte(stmtSlice[i].Search("actor").String()), &s)
fatalIfError(t, err)
err = group.ArrayAppendP(s, "actor.member")
fatalIfError(t, err)
}
// construct query
v := &url.Values{}
//t.Log(group.Search("actor").String())
v.Add("agent", group.Search("actor").String())
resp := getStatement(t, mart, v)
//t.Log(string(resp))
respstmt, err := gabs.ParseJSON(resp)
fatalIfError(t, err)
cnt, err := respstmt.ArrayCount("statements")
fatalIfError(t, err)
if cnt != len(ids) {
t.Fatalf("Expected %d statements in response; got %d", len(ids), cnt)
}
children, err := respstmt.S("statements").Children()
fatalIfError(t, err)
for idx, stm := range children {
if id, ok := stm.Search("id").Data().(string); !ok || id != ids[idx] {
t.Fatalf("Got invalid order of statement array")
}
}
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:56,代码来源:statement_fetch_test.go
示例3: saveGuestConfig
// Save guest configuration to path from JSON format.
func saveGuestConfig(config *gabs.Container, path string) (err error) {
s := config.String()
dst, err := os.Create(path)
if err != nil {
return
}
defer dst.Close()
_, err = dst.WriteString(s)
return
}
开发者ID:sjfloat,项目名称:docker-unikernel-runner,代码行数:11,代码来源:guest.go
示例4: appendOpenID
func appendOpenID(t *testing.T, stmt *gabs.Container) *gabs.Container {
stmt, err := gabs.ParseJSON([]byte(stmt.String()))
fatalIfError(t, err)
domainPrefix := uuid.NewV4().String()
openID := "http://" + domainPrefix + ".openid.example.com/"
_, err = stmt.SetP(openID, "actor.openid")
fatalIfError(t, err)
return stmt
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:11,代码来源:statement_fetch_test.go
示例5: PublicUserString
func PublicUserString(token *gabs.Container) string {
s, err := gabs.ParseJSON([]byte(token.String()))
if err != nil {
return "{}"
}
s.SetP("", "privid")
s.SetP("", "alertaddress")
return s.String()
}
开发者ID:timbwhitt,项目名称:assemble-web-chat,代码行数:11,代码来源:service.go
示例6: scrapeTimers
func (e *Exporter) scrapeTimers(json *gabs.Container) {
elements, _ := json.ChildrenMap()
for key, element := range elements {
new, err := e.scrapeTimer(key, element)
if err != nil {
log.Debug(err)
} else if new {
log.Infof("Added timer %q\n", key)
}
}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:11,代码来源:exporter.go
示例7: appendMbox
func appendMbox(t *testing.T, stmt *gabs.Container) *gabs.Container {
stmt, err := gabs.ParseJSON([]byte(stmt.String()))
fatalIfError(t, err)
domainPrefix := uuid.NewV4().String()
mbox := "mbox:[email protected]" + domainPrefix + ".example.com"
_, err = stmt.SetP(mbox, "actor.mbox")
fatalIfError(t, err)
return stmt
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:11,代码来源:statement_fetch_test.go
示例8: 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
示例9: 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
示例10: appendMboxSHA1
func appendMboxSHA1(t *testing.T, stmt *gabs.Container) *gabs.Container {
stmt, err := gabs.ParseJSON([]byte(stmt.String()))
fatalIfError(t, err)
data := make([]byte, 16)
_, err = rand.Read(data)
fatalIfError(t, err)
mboxSHA1 := fmt.Sprintf("%x", sha1.Sum(data))
_, err = stmt.SetP(mboxSHA1, "actor.mbox_sha1sum")
fatalIfError(t, err)
return stmt
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:13,代码来源:statement_fetch_test.go
示例11: 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
示例12: scrapeApps
func (e *Exporter) scrapeApps(json *gabs.Container, ch chan<- prometheus.Metric) {
elements, _ := json.S("apps").Children()
states := map[string]string{
"running": "tasksRunning",
"staged": "tasksStaged",
"healthy": "tasksHealthy",
"unhealthy": "tasksUnhealthy",
"cpus": "cpus",
"mem_in_mb": "mem",
"disk_in_mb": "disk",
"gpus": "gpus",
"avg_uptime": "taskStats.startedAfterLastScaling.stats.lifeTime.averageSeconds",
}
name := "app_instances"
gauge, new := e.Gauges.Fetch(name, "Marathon app instance count", "app")
if new {
log.Infof("Added gauge %q\n", name)
}
gauge.Reset()
for _, app := range elements {
id := app.Path("id").Data().(string)
data := app.Path("instances").Data()
count, ok := data.(float64)
if !ok {
log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of app instances\n", data))
continue
}
gauge.WithLabelValues(id).Set(count)
for key, value := range states {
name := fmt.Sprintf("app_task_%s", key)
gauge, new := e.Gauges.Fetch(name, fmt.Sprintf("Marathon app task %s count", key), "app")
if new {
log.Infof("Added gauge %q\n", name)
}
data := app.Path(value).Data()
count, ok := data.(float64)
if !ok {
log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of \"%s\" tasks\n", data, key))
continue
}
gauge.WithLabelValues(id).Set(count)
}
}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:50,代码来源:exporter.go
示例13: 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
示例14: scrapeHistogram
func (e *Exporter) scrapeHistogram(key string, json *gabs.Container) (bool, error) {
count, ok := json.Path("count").Data().(float64)
if !ok {
return false, errors.New(fmt.Sprintf("Bad historgram! %s has no count\n", key))
}
name := renameMetric(key)
help := fmt.Sprintf(histogramHelp, key)
counter, new := e.Counters.Fetch(name+"_count", help)
counter.WithLabelValues().Set(count)
percentiles, _ := e.Gauges.Fetch(name, help, "percentile")
max, _ := e.Gauges.Fetch(name+"_max", help)
mean, _ := e.Gauges.Fetch(name+"_mean", help)
min, _ := e.Gauges.Fetch(name+"_min", help)
stddev, _ := e.Gauges.Fetch(name+"_stddev", help)
properties, _ := json.ChildrenMap()
for key, property := range properties {
switch key {
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,代码行数:45,代码来源:exporter.go
示例15: PushEvent
// TODO: Properly get commit count
func PushEvent(data *gabs.Container) {
repo, _ := data.S("repository", "full_name").Data().(string)
user, _ := data.S("pusher", "name").Data().(string)
gitio := GitioShort(data.S("head_commit", "url").Data().(string))
commits, _ := data.S("commits").Children()
cobj, _ := data.S("commits").ChildrenMap()
fmt.Printf("[!] Commit # %d\n", len(cobj))
commitlen := strconv.Itoa(len(cobj))
message <- "[" + repo + "] " + user + " pushed " + commitlen + " commits " + gitio
for _, commit := range commits {
hash := commit.S("id").Data().(string)[0:6]
msg := commit.S("message").Data().(string)
user := commit.S("author", "name").Data().(string)
message <- "[" + repo + "] " + user + " " + hash + " - " + msg
}
}
开发者ID:XAMPP,项目名称:Gakin,代码行数:21,代码来源:main.go
示例16: 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
示例17: testGetMultStatementOfActor
func testGetMultStatementOfActor(t *testing.T, stmt *gabs.Container) {
db := initDatabase(t)
defer db.Close()
mart := initHandler(db)
id1 := uuid.NewV4().String()
id2 := uuid.NewV4().String()
putStatement(t, mart, stmt.String(), id1)
putStatement(t, mart, stmt.String(), id2)
// construct query
v := &url.Values{}
v.Add("agent", stmt.Search("actor").String())
respstmt, err := gabs.ParseJSON(getStatement(t, mart, v))
fatalIfError(t, err)
cnt, err := respstmt.ArrayCount("statements")
fatalIfError(t, err)
if cnt != 2 {
t.Fatalf("Expected 2 statements in response; got %d", cnt)
}
s0, err := respstmt.ArrayElement(0, "statements")
fatalIfError(t, err)
if id, ok := s0.Search("id").Data().(string); !ok || id != id1 {
t.Fatalf("Got invalid order of statement array")
}
s1, err := respstmt.ArrayElement(1, "statements")
fatalIfError(t, err)
if id, ok := s1.Search("id").Data().(string); !ok || id != id2 {
t.Fatalf("Got invalid order of statement array")
}
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:36,代码来源:statement_fetch_test.go
示例18: appendAccount
func appendAccount(t *testing.T, stmt *gabs.Container) *gabs.Container {
stmt, err := gabs.ParseJSON([]byte(stmt.String()))
fatalIfError(t, err)
suffix := uuid.NewV4().String()
name := "name-example-" + suffix
homePage := "http://example.com"
_, err = stmt.SetP(name, "actor.account.name")
fatalIfError(t, err)
_, err = stmt.SetP(homePage, "actor.account.homePage")
fatalIfError(t, err)
return stmt
}
开发者ID:realglobe-Inc,项目名称:edo-xrs,代码行数:14,代码来源:statement_fetch_test.go
示例19: 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
示例20: SendMessage
func SendMessage(cn, msg, cid string, container *gabs.Container) {
counter[cid]++
t := time.Now()
timestr := t.Format(time.RFC3339Nano)
container.Set(timestr, "timestamp")
container.Set(UserId, "userid")
container.Set(counter[cid], "counter")
container.Set(ClusterId, "clusterid")
container.Set(UUID, "uuid")
container.Set(IP, "ip")
container.Set(Hostname, "hostname")
ars := strings.Split(cn, " ")
if len(ars) == 3 {
container.Set(ars[0], "typename")
container.Set(ars[1], "taskid")
container.Set(ars[2], "ports")
container.Set(msg, "msg")
} else {
container.Set("", "msg")
}
}
开发者ID:Dataman-Cloud,项目名称:logspout,代码行数:21,代码来源:util.go
注:本文中的github.com/jeffail/gabs.Container类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论