本文整理汇总了Golang中github.com/jeffail/gabs.Container.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.String方法的具体用法?Golang Container.String怎么用?Golang Container.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jeffail/gabs.Container
的用法示例。
在下文中一共展示了Container.String方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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()
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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")
}
}
示例8: 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[:]))
}
}
}