本文整理匯總了Golang中github.com/eaciit/toolkit.Result.Data方法的典型用法代碼示例。如果您正苦於以下問題:Golang Result.Data方法的具體用法?Golang Result.Data怎麽用?Golang Result.Data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eaciit/toolkit.Result
的用法示例。
在下文中一共展示了Result.Data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Test1
func Test1(t *testing.T) {
t.Skip()
fmt.Println("Test 1 - Generate x Number")
numCount := 1000
workerCount := 100
idxs := make([]interface{}, numCount)
want := 0
for i := 1; i <= numCount; i++ {
idxs[i-1] = i
want += i
}
total := 0
fmt.Printf("Run Parallel %d job within %d pools \n", numCount, workerCount)
pr := Run(idxs, workerCount, func(js <-chan interface{}, rs chan<- *toolkit.Result) {
for j := range js {
time.Sleep(1 * time.Microsecond)
j2 := j.(int)
total += j2
r := new(toolkit.Result)
r.Status = toolkit.Status_OK
r.Data = j2
rs <- r
}
})
if total == want && pr.Success == 1000 {
fmt.Printf("Test OK in %v \n\n", pr.Duration)
} else {
fmt.Printf("Test Fail want %d got %d and has %d records\n", total, want, pr.Success)
}
}
示例2: TestDb2
func TestDb2(t *testing.T) {
fmt.Println("Test 2b - Insert Data (Parallel)")
numCount := pnumCount
workerCount := pworkerCount
idxs := make([]interface{}, numCount)
for i := 1; i <= numCount; i++ {
idxs[i-1] = i + 2000
}
conn := mongodb.NewConnection("localhost:27888", "root", "Database.1", "ectest")
//conn := mongodb.NewConnection("localhost:27888", "", "", "ectest")
e = conn.Connect()
if e != nil {
t.Error("Unable to connect to Database | " + e.Error())
return
}
defer conn.Close()
_, e = conn.Execute("appusers", toolkit.M{"find": toolkit.M{}, "operation": base.DB_DELETE})
if e != nil {
fmt.Println("Unable to delete: " + e.Error())
}
fmt.Printf("Insert %d data within %d pools \n", numCount, workerCount)
pr := Run(idxs, workerCount, func(js <-chan interface{}, rs chan<- *toolkit.Result) {
for jb := range js {
j := jb.(int)
user := toolkit.M{}
userid := "User " + strconv.Itoa(j)
user.Set("_id", userid)
user.Set("fullname", "User "+strconv.Itoa(j))
user.Set("email", "user"+strconv.Itoa(j)+"@email.com")
r := new(toolkit.Result)
//_, _, e = conn.Query().From("ORMUsers").Save(user).Run()
_, e := conn.Execute("appusers",
toolkit.M{"find": toolkit.M{"_id": userid}, "operation": base.DB_SAVE, "data": user})
if e == nil {
r.Status = toolkit.Status_OK
r.Data = user
} else {
r.Status = toolkit.Status_NOK
r.Message = "Error ID " + strconv.Itoa(j) + " " + e.Error()
}
rs <- r
}
})
if pr.Success == numCount {
fmt.Printf("Test OK in %v \n\n", pr.Duration)
} else {
fmt.Printf("Test Fail has %d records. \nErrors\n%v\nIn %v \n\n", pr.Success, toolkit.JsonString(pr.Errors[0]), pr.Duration)
}
}