a parse.com REST API client library for go
go get -u github.com/zx9597446/go-parse
- config client:
var parseClient = parse.NewClient()
parseClient.AppId = ""
parseClient.AppKey = ""
parseClient.DebugRequest = true
- Object CRUD
className := "TestClass"
o := parse.NewObject()
o.Set("key", "value")
fetchOnSave := true
o.Create(parseClient, className, fetchOnSave)
o.Set("newKey", "newValue")
o.Update(parseClient, className)
o2 := parse.NewObject()
oid := o.ObjectId()
o2.Fetch(parseClient, className, oid, "")
o2.Delete(parseClient, className)
- call cloud function:
param := parse.NewParams()
param["key"] = "value"
ret, err := parseClient.CallFunction("functionName", param.Encode())
- query objects (basic)
opt := QueryOptions{
Class: "PS",
Limit: DefaultLimit,
Skip: 0,
Order: "-createdAt'",
Keys: "",
Include: "",
Count: false,
}
r, err := QueryObjects(parseClient, opt)
if err != nil {
t.Fatal(err)
}
objs, _ := r.GetResults()
for _, o := range objs {
t.Log(o.ObjectId())
}
- query objects (advance)
where := NewWhere()
where.AddEqualTo("objectId", "abcd")
where.Add("someKey", OpLessThanOrEqualTo, 100)
opt := QueryOptions{
Class: "PS",
Limit: DefaultLimit,
Skip: 0,
Order: "-createdAt'",
Keys: "",
Include: "",
Count: false,
Where: where,
}
r, err := QueryObjects(parseClient, opt)
if err != nil {
t.Fatal(err)
}
objs, _ := r.GetResults()
for _, o := range objs {
t.Log(o.ObjectId())
}
see doc
see test