本文整理匯總了Golang中github.com/eaciit/toolkit.Printf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Printf函數的具體用法?Golang Printf怎麽用?Golang Printf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Printf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSelect
func TestSelect(t *testing.T) {
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().From(tableName).Where(dbox.Eq("Age", "34")).Cursor(nil)
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
// if cursor.Count() == 0 {
// t.Fatalf("No record found")
// }
var datas []toolkit.M
e = cursor.Fetch(&datas, 2, false)
if e != nil {
t.Fatalf("Fetch error: %s", e.Error())
}
// if len(datas) != cursor.Count() {
// t.Fatalf("Expect %d records got %d\n%s\n", cursor.Count(), len(datas), toolkit.JsonString(datas))
// }
toolkit.Printf("Total Record : %d\n", cursor.Count())
toolkit.Printf("Record found: %d\nData:\n%s\n", len(datas), toolkit.JsonString(datas))
// toolkit.Printf("Record found: %d\nData:\n%s\n", len(datas),
// func() string {
// var ret []string
// for _, v := range datas {
// ret = append(ret, v.GetString("_id"))
// }
// return strings.Join(ret, ",")
// }())
}
示例2: DoMasterUnit
func (m *MigrateData) DoMasterUnit() error {
tStart := time.Now()
tk.Println("Starting MasterUnit..")
mod := new(MasterUnit)
c, e := m.BaseController.MongoCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
if e != nil {
return e
}
defer c.Close()
result := []tk.M{}
e = c.Fetch(&result, 0, false)
for _, val := range result {
val.Set("Unit", val.Get("_id").(string))
_, e := m.InsertOut(val, new(MasterUnit))
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n------------------------- \n", e.Error(), val)
return e
}
}
cr, e := m.BaseController.SqlCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
ctn := cr.Count()
cr.Close()
tk.Printf("Completed Success in %v | %v data(s)\n", time.Since(tStart), ctn)
return nil
}
示例3: TestTakeSkip
func TestTakeSkip(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Select("id", "productname").
From(tableProducts).
Take(5).
Skip(10).
Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
rets := []toolkit.M{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Fetch OK. Result: %v \n", toolkit.JsonString(rets))
toolkit.Printf("Total Record OK. Result: %v \n", toolkit.SliceLen(rets))
}
}
示例4: TestSelect
func TestSelect(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
// csr, e := c.NewQuery().Select().From("tes").Where(dbox.Eq("id", "3")).Cursor(nil)
csr, e := c.NewQuery().
// Select("empno", "ename", "hiredate").
From(tableCustomers).Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
rets := []toolkit.M{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch N: %s \n", e.Error())
} else {
toolkit.Printf("Fetch N OK. Result: %v \n", toolkit.JsonString(rets))
toolkit.Printf("Total Fetch OK : %v \n", toolkit.SliceLen(rets))
}
}
示例5: InsertBulk
func (b *BaseController) InsertBulk(result []tk.M, m orm.IModel, wg *sync.WaitGroup) {
var datas []orm.IModel
for _, i := range result {
valueType := reflect.TypeOf(m).Elem()
for f := 0; f < valueType.NumField(); f++ {
field := valueType.Field(f)
bsonField := field.Tag.Get("bson")
jsonField := field.Tag.Get("json")
if jsonField != bsonField && field.Name != "RWMutex" && field.Name != "ModelBase" {
i.Set(field.Name, GetMgoValue(i, bsonField))
}
switch field.Type.Name() {
case "string":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, "")
}
break
case "Time":
if GetMgoValue(i, bsonField) == nil {
i.Set(field.Name, time.Time{})
} else {
i.Set(field.Name, GetMgoValue(i, bsonField).(time.Time).UTC())
}
break
default:
break
}
}
newPointer := getNewPointer(m)
e := tk.Serde(i, newPointer, "json")
datas = append(datas, newPointer)
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n\n %#v \n------------------------- \n", e.Error(), i, newPointer)
wg.Done()
}
}
if nil != datas {
muinsert.Lock()
for {
e := b.Ctx.InsertBulk(datas)
if e == nil {
ctn := len(result)
idx += ctn
tk.Printf("saved: %v data(s)\n", idx)
break
} else {
b.Ctx.Connection.Connect()
}
}
muinsert.Unlock()
}
wg.Done()
}
示例6: TestGetObj
func TestGetObj(t *testing.T) {
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
//ObjTypeTable, ObjTypeView, ObjTypeProcedure, ObjTypeAll
toolkit.Printf("List Table : %v\n", c.ObjectNames(dbox.ObjTypeTable))
toolkit.Printf("List Procedure : %v\n", c.ObjectNames(dbox.ObjTypeProcedure))
toolkit.Printf("List All Object : %v\n", c.ObjectNames(""))
}
示例7: DoPowerPlantOutages
func (m *MigrateData) DoPowerPlantOutages() error {
tStart := time.Now()
tk.Println("Starting DoPowerPlantOutages..")
mod := new(PowerPlantOutages)
c, e := m.BaseController.MongoCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
if e != nil {
return e
}
defer c.Close()
result := []tk.M{}
e = c.Fetch(&result, 0, false)
for _, val := range result {
details := val.Get("Details").(interface{}).([]interface{})
val.Set("Details", nil)
_, e := m.InsertOut(val, new(PowerPlantOutages))
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n------------------------- \n", e.Error(), val)
return e
}
id := val.GetString("_id")
tk.Printf("%#v \n\n", id)
for _, detail := range details {
det := detail.(tk.M)
det.Set("POId", id)
tk.Println(det)
_, e = m.InsertOut(det, new(PowerPlantOutagesDetails))
if e != nil {
tk.Printf("\n----------- ERROR -------------- \n %v \n\n %#v \n------------------------- \n", e.Error(), det)
return e
}
}
}
cr, e := m.BaseController.SqlCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
ctn := cr.Count()
cr.Close()
tk.Printf("Completed Success in %v | %v data(s)\n", time.Since(tStart), ctn)
return nil
}
示例8: TestSelectAggregate
func TestSelectAggregate(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Select("productname").
Aggr(dbox.AggrSum, "price", "Total Price").
Aggr(dbox.AggrAvr, "price", "Avg").
From(tableProducts).
Group("productname").
Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
rets := []toolkit.M{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Fetch OK. Result: %v \n", toolkit.JsonString(rets))
}
}
示例9: TestSelectFilter
func TestSelectFilter(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
csr, e := c.NewQuery().
Select("empno", "ename", "mgr", "hiredate").
Where(dbox.Or(dbox.Eq("empno", 7521), dbox.Eq("ename", "ADAMS"))).
From(tableName).Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
rets := /*[]customers{}*/ []toolkit.M{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Filter OK. Result: %v \n", toolkit.JsonString(rets))
}
}
示例10: TestOdbc
func TestOdbc(t *testing.T) {
conn, e := odbc.Connect("DSN=mysql-dsn;UID=root;PWD=root")
if e != nil {
toolkit.Println("Conn Error found: ", e.Error())
}
toolkit.Println(conn)
query := "SELECT id, name FROM dummy"
stmt, e := conn.Prepare(query)
if e != nil {
toolkit.Println("STMT Error found: ", e.Error())
}
// toolkit.Println(conn, stmt)
e = stmt.Execute()
if e != nil {
toolkit.Println("Execute Error found: ", e.Error())
}
rows, e := stmt.FetchAll()
if e != nil {
toolkit.Println("FetchAll Error found: ", e.Error())
}
// toolkit.Println(toolkit.JsonString(rows))
for _, row := range rows {
toolkit.Printf("%v\n", row.Data)
}
stmt.Close()
conn.Close()
}
示例11: TestStorageWrite
func TestStorageWrite(t *testing.T) {
skipIfClientNil(t)
es := []string{}
toolkit.Printf("Writing Data:\n")
for i := 0; i < 200; i++ {
dataku := toolkit.RandInt(1000)
totalInt += dataku
//toolkit.Printf("%d ", dataku)
in := toolkit.M{}.Set("key", fmt.Sprintf("public.dataku.%d", i)).Set("data", toolkit.ToBytes(dataku, ""))
writeResult := client.Call("set", in)
if writeResult.Status != toolkit.Status_OK {
es = append(es, toolkit.Sprintf("Fail to write data %d : %d => %s", i, dataku, writeResult.Message))
}
}
if len(es) > 0 {
errorTxt := ""
if len(es) <= 10 {
errorTxt = strings.Join(es, "\n")
} else {
errorTxt = strings.Join(es[:10], "\n") + "\n... And others ..."
}
t.Errorf("Write data fail.\n%s", errorTxt)
}
}
示例12: TestFreeQuery
func TestFreeQuery(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Command("freequery", toolkit.M{}.
Set("syntax", "select name from tes where name like 'r%'")).
Cursor(nil)
if csr == nil {
t.Errorf("Cursor not initialized", e.Error())
return
}
defer csr.Close()
results := make([]map[string]interface{}, 0)
err := csr.Fetch(&results, 0, false)
if err != nil {
t.Errorf("Unable to fetch: %s \n", err.Error())
} else {
toolkit.Println("======================")
toolkit.Println("TEST FREE QUERY")
toolkit.Println("======================")
toolkit.Println("Fetch N OK. Result: ")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例13: TestSelect
func TestSelect(t *testing.T) {
// t.Skip()
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().
Select("id", "nama", "amount").
From(tableName).
Cursor(nil)
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
var results []toolkit.M
e = cursor.Fetch(&results, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Println("======================")
toolkit.Println(operation)
toolkit.Println("======================")
toolkit.Println(sintaks)
toolkit.Println("Number of rows", cursor.Count())
toolkit.Println("Fetch OK. Result:")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例14: DoGenerateTempMstPlant
func (m *MigrateData) DoGenerateTempMstPlant() error {
tStart := time.Now()
tk.Println("Starting DoGenerateTempMstPlant..")
mod := new(TempMstPlant)
c, e := m.BaseController.MongoCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
if e != nil {
return e
}
defer c.Close()
result := []tk.M{}
e = c.Fetch(&result, 0, false)
_ = tStart
for _, val := range result {
for {
_, e := m.InsertOut(val, new(TempMstPlant))
if e == nil {
break
} else {
m.SqlCtx.Connection.Connect()
}
}
}
cr, e := m.BaseController.SqlCtx.Connection.NewQuery().From(mod.TableName()).Cursor(nil)
ctn := cr.Count()
cr.Close()
tk.Printf("Completed Success in %v | %v data(s)\n", time.Since(tStart), ctn)
return nil
}
示例15: TestFrom
func TestFrom(t *testing.T) {
for i := 0; i < sampleCount; i++ {
obj := Obj{}
obj.F = toolkit.ToFloat64(toolkit.RandInt(1000), 2, toolkit.RoundingAuto)
obj.I = toolkit.RandInt(1000) + 5
objs = append(objs, obj)
if i == 0 {
min = obj.I
max = obj.I
sum = obj.I
avg = toolkit.ToFloat64(obj.I, 4, toolkit.RoundingAuto)
} else {
sum += obj.I
avg = toolkit.ToFloat64(sum, 4, toolkit.RoundingAuto) /
toolkit.ToFloat64(i+1, 4, toolkit.RoundingAuto)
if min > obj.I {
min = obj.I
}
if max < obj.I {
max = obj.I
}
}
}
c = crowd.From(&objs)
check(t, c.Error, "")
toolkit.Printf("Data len: %d, max: %d, min: %d, sum: %d, avg: %5.4f\n", c.Len(), max, min, sum, avg)
}