本文整理匯總了Golang中github.com/hiromaily/golibs/log.Debugf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debugf函數的具體用法?Golang Debugf怎麽用?Golang Debugf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debugf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSetDataToStruct
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
func TestSetDataToStruct(t *testing.T) {
//tu.SkipLog(t)
//var columns = []string{"field1", "field2", "field3"}
//values := []interface{}{10, "Harry", "Japan"}
values := make([][]interface{}, 2)
values[0] = []interface{}{10, "Harry", "UK"}
values[1] = []interface{}{15, "Hiroki", "Japan"}
//1.struct
//*
var techerInfo TeacherInfo
err := SetDataToStruct(values, &techerInfo)
if err != nil {
t.Errorf("[01]SetDataToStruct: error: %s", err)
}
lg.Debugf("techerInfo:%#v", techerInfo)
//*/
//2.slice struct
//*
var techerInfos []TeacherInfo
err = SetDataToStruct(values, &techerInfos)
if err != nil {
t.Errorf("[02]SetDataToStruct: error: %s", err)
}
lg.Debugf("techerInfo:%#v", techerInfos)
//*/
}
示例2: LoadJSONFile
// LoadJSONFile is to load json file
func LoadJSONFile(filePath string) *SiteInfo {
lg.Debug("load json file")
//initialize
siteInfo = SiteInfo{}
//test(get current dir)
//dir := path.Dir(os.Args[0])
//lg.Debugf("path.Dir(os.Args[0]): %s", dir)
// Loading jsonfile
if filePath == "" {
//dir := path.Dir(os.Args[0])
//lg.Debugf("path.Dir(os.Args[0]): %s", dir)
//filePath = fmt.Sprintf("%s/json/teachers.json", dir)
lg.Fatal("json filepath have to be set.")
return nil
}
file, _ := ioutil.ReadFile(filePath)
err := json.Unmarshal(file, &siteInfo)
if err != nil {
lg.Fatalf("json format is invalid: %v, filepath is %s", err, filePath)
return nil
}
lg.Debugf("SiteInfo.Url: %v", siteInfo.URL)
lg.Debugf("SiteInfo.Teachers[0].Id: %d, Name: %s, Country: %s", siteInfo.Teachers[0].ID, siteInfo.Teachers[0].Name, siteInfo.Teachers[0].Country)
return &siteInfo
}
示例3: TestGetAllData
func TestGetAllData(t *testing.T) {
//tu.SkipLog(t)
mg := GetMongo()
mg.GetCol(testColUser)
//#1
var users []User
err := mg.C.Find(nil).Sort("age").All(&users)
if err != nil {
t.Errorf("mg.C.Find(nil).Sort(\"age\").All(&users) / error:%s", err)
}
//t.Logf("result users by find.all: %+v", users)
//#2 unclear format of json
mg.GetCol(testColTeacher)
var v []map[string]interface{}
err = mg.C.Find(nil).All(&v)
if err != nil {
t.Errorf("mg.C.Find(nil).All(&v) / error:%s", err)
//result argument must be a slice address
}
lg.Debugf("result unclear map data by find.all: %+v", v)
lg.Debugf("result url: %s", v[0]["url"])
}
示例4: TestGetOneDataByColumn
//-----------------------------------------------------------------------------
// READ
//-----------------------------------------------------------------------------
func TestGetOneDataByColumn(t *testing.T) {
//tu.SkipLog(t)
mg := GetMongo()
mg.GetCol(testColUser)
searchName := "Ken"
user := new(User)
//find
err := mg.FindOne(bson.M{"name": searchName}, user)
//mg.C.Find(bson.M{"name": searchName}).One(user)
if err != nil {
t.Errorf("mg.FindOne(bson.M{\"name\": searchName}, user) / error:%s", err)
//error:not found
}
lg.Debugf("user_id is %v", user.ID)
lg.Debugf("result user by find: %v", *user)
//save
savedUserID = GetObjectID(user.ID)
lg.Debugf("savedUserID is %s", savedUserID)
}
示例5: TestSelectInsScanOne2
//plus placeholder
func TestSelectInsScanOne2(t *testing.T) {
db := getMySQL().Db
//1.int
var userID int
sql := "SELECT user_id FROM t_users WHERE delete_flg=?"
b := db.SelectIns(sql, 0).ScanOne(&userID)
if db.Err != nil {
t.Fatalf("[1]db.SelectIns(): %s", db.Err)
}
lg.Debugf("user_id is %d, result is %v", userID, b)
//2.string
var firstName string
sql = "SELECT first_name FROM t_users WHERE delete_flg=?"
b = db.SelectIns(sql, 0).ScanOne(&firstName)
if db.Err != nil {
t.Fatalf("[2]db.SelectIns(): %s", db.Err)
}
lg.Debugf("firstName is %s, result is %v", firstName, b)
//3.string
var updated string
sql = "SELECT update_datetime FROM t_users WHERE delete_flg=?"
b = db.SelectIns(sql, 0).ScanOne(&updated)
if db.Err != nil {
t.Fatalf("[3]db.SelectIns(): %s", db.Err)
}
lg.Debugf("update_datetime is %s, result is %v", updated, b)
}
示例6: TestSelectInsScanOneJSON
//JSON Type without placeholder
func TestSelectInsScanOneJSON(t *testing.T) {
tu.SkipLog(t)
db := getMySQL().Db
//1.Json Data as string
var memo string
sql := "SELECT memo2 FROM t_invoices"
b := db.SelectIns(sql).ScanOne(&memo)
if db.Err != nil {
t.Fatalf("[1]db.SelectIns(): %s", db.Err)
}
lg.Debugf("memo2 is %s, result is %v", memo, b)
//convert string to slice
var converted []int
json.Unmarshal([]byte(memo), &converted)
lg.Debugf("converted memo2 is %v", converted)
//2.Json Data as Array (This is not correct)
var memo2 []int
sql = "SELECT memo2 FROM t_invoices"
b = db.SelectIns(sql).ScanOne(&memo2)
if db.Err != nil {
t.Fatalf("[2]db.SelectIns(): %s", db.Err)
}
lg.Debugf("memo2 is %s, result is %v", memo2, b)
}
示例7: TestInsertOne
//-----------------------------------------------------------------------------
// CREATE
//-----------------------------------------------------------------------------
// insert one record
func TestInsertOne(t *testing.T) {
//tu.SkipLog(t)
mg := GetMongo()
mg.GetCol(testColUser)
// test data
works := []Work{{Occupation: "programmer", CompanyId: 1}, {Occupation: "programmer", CompanyId: 2}}
address := Address{ZipCode: "1060047", Country: "Japan", City: "Tokyo", Address1: "港區南麻布2-9-7", Address2: "マンション101"}
user := User{Name: "Harry", Age: 25, Address: address, Works: works, CreatedAt: time.Now()}
// insert
err := mg.C.Insert(&user)
if err != nil {
t.Errorf("mg.C.Insert(&user) / error:%s", err)
}
// check length
cnt, err := mg.C.Count()
lg.Debugf("count:%d, err = %s", cnt, err)
//TODO: Local Time
//time:2016-07-14 16:57:39.550187911 +0900 JST
lg.Debugf("time:%v", user.CreatedAt.Local())
}
示例8: callerDebug
//-----------------------------------------------------------------------------
// functions
//-----------------------------------------------------------------------------
// CallerDebug is just sample of runtime.Caller
func callerDebug(skip int) {
programCounter, sourceFileName, sourceFileLineNum, ok := runtime.Caller(skip)
lg.Debugf("ok: %t", ok)
lg.Debugf("programCounter: %v", programCounter)
lg.Debugf("sourceFileName: %s", sourceFileName)
lg.Debugf("sourceFileLineNum: %d", sourceFileLineNum)
lg.Debug("- - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
//0.1.2...と増える毎に呼び出し元を辿っていく
//_, file, line, ok = runtime.Caller(calldepth)
//pc, src, line, ok := runtime.Caller(0)
//fmt.Println(pc, src, line, ok)
//runtime.Caller(0)->582751 {GOPATH}/src/github.com/hiromaily/golibs/log/log.go 138 true
//pc, src, line, ok = runtime.Caller(1)
//fmt.Println(pc, src, line, ok)
//8525 {GOPATH}/src/github.com/hiromaily/goweb/ginserver.go 20 true
//pc, src, line, ok = runtime.Caller(2)
//fmt.Println(pc, src, line, ok)
//11667 {GOPATH}/src/github.com/hiromaily/goweb/ginserver.go 100 true
//PrintStack prints to standard error the stack trace returned by runtime.Stack.
debug.PrintStack()
}
示例9: CheckByte
// CheckByte is to check nil argument at []byte type
func CheckByte(val []byte) {
//cannot use nil as type bool in argument
lg.Debugf("CheckByte: %v", val)
var defaultData []byte
lg.Debugf("CheckByte2: %v", defaultData)
}
示例10: TestCommonUsingDo
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//EXPIRE(key, seconds), TTL(key), INFO
//-----------------------------------------------------------------------------
func TestCommonUsingDo(t *testing.T) {
//tu.SkipLog(t)
sleepS := 2
c := GetRedis().Conn
c.Do("MSET", "key1", 20, "key2", 30)
c.Do("HMSET", "key3:subkey1", "field1", 1, "field2", 2)
c.Do("HMSET", "key3:subkey2", "field1", 99, "field2", 100)
val, err := redis.Int(c.Do("GET", "key1"))
if err != nil {
t.Errorf("key1 is 10: value is %v, error is %s", val, err)
}
fields, err := redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
if err != nil {
t.Errorf("field1 should be 1, field2 should be 1 but result is %#v, error is %s", fields, err)
}
//EXPIRE
c.Do("EXPIRE", "key1", sleepS)
c.Do("EXPIRE", "key3:subkey1", sleepS)
//TTL
s, err := redis.Int(c.Do("TTL", "key1"))
if err != nil {
t.Errorf("redis.Int(c.Do(\"TTL\", \"key1\")) error : %s", err)
}
lg.Debugf("TTL is %v", s)
//sleep
time.Sleep(time.Duration(sleepS+1) * time.Second)
s, _ = redis.Int(c.Do("TTL", "key1"))
lg.Debugf("TTL is %v", s)
//It can't access
val, err = redis.Int(c.Do("GET", "key1"))
if err == nil {
t.Errorf("key1 has already expired: value is %v", val)
}
//It can't access
//TODO:somehow it can access. but value is 0
fields, err = redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
//if err == nil {
if err != nil || fields[0] != 0 || fields[1] != 0 {
t.Errorf("key3:subkey1 has already expired: value is %+v", fields)
}
//It's OK.
fields, err = redis.Ints(c.Do("HMGET", "key3:subkey2", "field1", "field2"))
if err != nil {
//if err != nil || fields[0] != 99 || fields[1] != 100 {
t.Errorf("field1 should be 99, field2 should be 100 but result is %#v", fields)
}
}
示例11: CheckInterfaceWhenPointer
// CheckInterfaceWhenPointer is to check pointer argument in interface{} type
func CheckInterfaceWhenPointer(val interface{}) {
//0xc82000e640
lg.Debugf("CheckInterfaceWhenPointer: %v", val)
v := reflect.ValueOf(val)
lg.Debugf("CheckInterfaceWhenPointer v.Type(): %v", v.Type()) //*int
lg.Debugf("CheckInterfaceWhenPointer v.Kind(): %v", v.Kind()) //ptr
}
示例12: TestGetRedisInfo
func TestGetRedisInfo(t *testing.T) {
host, pass, port, err := GetRedisInfo("redis://h:[email protected].com:20819")
if err != nil {
t.Errorf("GetRedisInfo error: %s", err)
}
lg.Debugf("host: %s", host)
lg.Debugf("pass: %s", pass)
lg.Debugf("port: %d", port)
}
示例13: TestUpdateOneDataById
func TestUpdateOneDataById(t *testing.T) {
//tu.SkipLog(t)
mg := GetMongo()
mg.GetCol(testColUser)
//TODO:this is must be gotten automatically
//get top record
//userId := "57871a3e340e7601939628e1"
userId := savedUserID
idQueryier := bson.ObjectIdHex(userId)
//oids := make([]bson.ObjectId, len(ids))
//for i := range ids {
// oids[i] = bson.ObjectIdHex(ids[i])
//}
//query := bson.M{"_id": bson.M{"$in": oids}}
// #1. Update (only one record)
updateData := bson.M{"$set": bson.M{"age": 14, "createdAt": time.Now()}}
err := mg.C.UpdateId(idQueryier, updateData)
if err != nil {
t.Errorf("mg.C.UpdateId(idQueryier, updateData) / error:%s", err)
}
// check
user := new(User)
mg.C.Find(bson.M{"_id": bson.ObjectIdHex(userId)}).One(user)
lg.Debugf("result user by find id: %v", *user)
lg.Debug("- - - - - - - - - - - - - - - - - -")
// #2. Update (nested element)
updateData = bson.M{"$set": bson.M{"address.country": "UK", "createdAt": time.Now()}}
err = mg.C.UpdateId(idQueryier, updateData)
if err != nil {
t.Errorf("mg.C.UpdateId(idQueryier, updateData) / error:%s", err)
}
// check
user2 := new(User)
mg.C.Find(bson.M{"_id": bson.ObjectIdHex(userId)}).One(user2)
lg.Debugf("result user by find id: %v", *user2)
lg.Debug("- - - - - - - - - - - - - - - - - -")
// #3. Update (update by adding element on array)
updateData = bson.M{"$push": bson.M{"works": bson.M{"occupation": "banker", "company_id": 9}}}
err = mg.C.UpdateId(idQueryier, updateData)
if err != nil {
t.Errorf("mg.C.UpdateId(idQueryier, updateData) / error:%s", err)
}
// check
mg.C.Find(bson.M{"_id": bson.ObjectIdHex(userId)}).One(user2)
lg.Debugf("result user by find id: %v", *user2)
lg.Debug("- - - - - - - - - - - - - - - - - -")
}
示例14: TestCurrentFunc
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
func TestCurrentFunc(t *testing.T) {
//tu.SkipLog(t)
s := CurrentFunc(1)
if s != "TestCurrentFunc" {
t.Errorf("result of CurrentFunc(1) is wrong: %s", s)
}
lg.Debugf("CurrentFunc(1) :%s", s)
b := CurrentFuncV2()
lg.Debugf("CurrentFunc2() :%s", b)
}
示例15: TestGetMySQLInfo
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
func TestGetMySQLInfo(t *testing.T) {
host, dbname, user, pass, err := GetMySQLInfo("mysql://be2ebea7cda583:[email protected]/heroku_aa95a7f43af0311?reconnect=true")
if err != nil {
//unexpected EOF
t.Errorf("GetMySQLInfo error: %s", err)
}
lg.Debugf("host: %s", host)
lg.Debugf("dbname: %s", dbname)
lg.Debugf("user: %s", user)
lg.Debugf("pass: %s", pass)
}