本文整理汇总了Golang中featen/ags/modules/log.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Encode
func Encode(p string) string {
key := []byte(sysMagicNumber)
plaintext := []byte(p)
block, err := aes.NewCipher(key)
if err != nil {
log.Debug("%v", err)
return ""
}
// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
log.Debug("%v", err)
return ""
}
stream := cipher.NewCFBEncrypter(block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
// It's important to remember that ciphertexts must be authenticated
// (i.e. by using crypto/hmac) as well as being encrypted in order to
// be secure.
return fmt.Sprintf("%x\n", ciphertext)
}
示例2: dbFindCustomersByCond
func dbFindCustomersByCond(cond string) ([]Customer, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
sqlCond, limit, offset := buildSqlCond(cond)
log.Debug("get customers for %s", cond)
querySql := fmt.Sprintf("SELECT id, name, cover_photo, desc, phone, email FROM user WHERE type=1 AND %s LIMIT %d OFFSET %d ", sqlCond, limit, offset)
stmt, err := dbHandler.Prepare(querySql)
if err != nil {
log.Debug("querySql: %s", querySql)
log.Error("Prepare failed : %v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
log.Fatal("Query customers failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
customers := make([]Customer, 0, limit)
for rows.Next() {
var customerId sql.NullInt64
var name, coverPhoto, desc, phone, email sql.NullString
rows.Scan(&customerId, &name, &coverPhoto, &desc, &phone, &email)
customers = append(customers, Customer{strconv.FormatInt(customerId.Int64, 10), name.String, coverPhoto.String, "", phone.String, email.String, nil})
}
return customers, http.StatusOK
}
示例3: dbSaveCustomer
func dbSaveCustomer(c *Customer) int {
log.Debug("try to save user %v", c)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
var userType = 1
if len(c.Email) == 0 {
userType = 2
}
stmt, err := dbHandler.Prepare("UPDATE user SET type=?, name=?, email=?, cover_photo=?, phone=?, desc=? WHERE id=?")
if err != nil {
log.Error("%v", err)
return http.StatusInternalServerError
}
defer stmt.Close()
_, err = stmt.Exec(userType, c.Name, c.Email, c.CoverPhoto, c.Phone, c.Desc, c.Id)
if err != nil {
log.Error("%v", err)
return http.StatusBadRequest
}
return http.StatusOK
}
示例4: dbSearchCustomers
func dbSearchCustomers(t string, p int) ([]Customer, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
offset := customerPageLimit * (p - 1)
querySql := fmt.Sprintf("select id, name, cover_photo, phone, desc, email from user where type=1 and (name like '%%%s%%' or phone like '%%%s%%' or email like '%%%s%%') order by id limit %d offset %d", t, t, t, customerPageLimit, offset)
stmt, err := dbHandler.Prepare(querySql)
if err != nil {
log.Debug("querySql: %s", querySql)
log.Error("Prepare failed : %v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
log.Fatal("Query customers failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
customers := make([]Customer, 0)
for rows.Next() {
var customerId sql.NullInt64
var name, coverPhoto, phone, desc, email sql.NullString
rows.Scan(&customerId, &name, &coverPhoto, &phone, &desc, &email)
customers = append(customers, Customer{strconv.FormatInt(customerId.Int64, 10), name.String, coverPhoto.String, desc.String, phone.String, email.String, nil})
}
return customers, http.StatusOK
}
示例5: dbCreateCustomer
func dbCreateCustomer(c *Customer) int {
log.Debug("try to create user %v", c)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
var userType = 1
if len(c.Email) == 0 {
userType = 2
}
stmt, err := dbHandler.Prepare("INSERT INTO user (type, name, email, cover_photo, phone, desc) VALUES (?,?,?,?,?,?)")
if err != nil {
log.Error("%v", err)
return http.StatusInternalServerError
}
defer stmt.Close()
_, err = stmt.Exec(userType, c.Name, c.Email, c.CoverPhoto, c.Phone, c.Desc)
if err != nil {
log.Error("%v", err)
return http.StatusBadRequest
}
return http.StatusOK
}
示例6: dbFindCustomer
func dbFindCustomer(c *Customer) int {
log.Debug("get customer detail for %d", c.Id)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
querySql := "SELECT id, name, cover_photo, desc, phone, email FROM user WHERE type in (1,2) AND id=? "
var id sql.NullInt64
var name, coverPhoto, desc, phone, email sql.NullString
err = dbHandler.QueryRow(querySql, c.Id).Scan(&id, &name, &coverPhoto, &desc, &phone, &email)
if err != nil {
if err == sql.ErrNoRows {
log.Info("No customer found for %d", c.Id)
return http.StatusNotFound
} else {
log.Debug("sql : %s", querySql)
log.Error("DB query failed: %v", err)
return http.StatusInternalServerError
}
}
c.Name = name.String
c.CoverPhoto = coverPhoto.String
c.Desc = desc.String
c.Phone = phone.String
c.Email = email.String
queryLogSql := "SELECT operation_type, operation_detail, operation_time FROM user_log WHERE user_id=? ORDER BY id DESC LIMIT 100"
rows, err := dbHandler.Query(queryLogSql, c.Id)
defer rows.Close()
logs := make([]CustomerLog, 0, 100)
for rows.Next() {
var operation_type, operation_detail sql.NullString
var operation_time time.Time
rows.Scan(&operation_type, &operation_detail, &operation_time)
logs = append(logs, CustomerLog{c.Id, operation_type.String, operation_detail.String, operation_time.Format(timeLayout)})
}
c.Logs = logs
return http.StatusOK
}
示例7: findCustomersByCond
func findCustomersByCond(req *restful.Request, resp *restful.Response) {
log.Debug("try to find customers with cond : %s", req.PathParameter("cond"))
cond := req.PathParameter("cond")
customers, ret := dbFindCustomersByCond(cond)
if ret == http.StatusOK {
resp.WriteEntity(customers)
} else {
resp.WriteErrorString(ret, http.StatusText(ret))
}
}
示例8: sendRecover
func sendRecover(req *restful.Request, resp *restful.Response) {
var ru VerifyUser
err := req.ReadEntity(&ru)
if err != nil {
log.Debug("read recover user info %s failed", ru.Email)
resp.WriteErrorString(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
} else {
exist := dbEmailExist(ru.Email)
if !exist {
log.Debug("not a valid email %s", ru.Email)
resp.WriteErrorString(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
} else {
magic := auth.GenMagic(ru.Email, time.Now().String())
dbInsertRecoverInfo(ru.Email, magic)
go mails.SendRecoverMail(ru.Email, magic)
resp.WriteHeader(http.StatusOK)
}
}
}
示例9: signoutUser
func signoutUser(req *restful.Request, resp *restful.Response) {
var id SignoutUser
err := req.ReadEntity(&id)
if err == nil {
auth.DelCookie(req, resp, id.Id)
} else {
log.Debug("sign out id %s failed", id.Id)
resp.WriteErrorString(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
}
}
示例10: AuthFilter
func AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
b, userid := AuthHandler(req.Request, resp.ResponseWriter)
if !b {
log.Debug("unauthorized request %s %s", req.Request.Method, req.Request.URL)
resp.WriteErrorString(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
return
}
req.SetAttribute("agsuserid", userid)
chain.ProcessFilter(req, resp)
}
示例11: updateReviewboardOwner
func updateReviewboardOwner(req *http.Request, id string) {
log.Debug("Update Reviewboard Owner")
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
b, vid := AuthVisitorHandler(req, nil)
if !b {
log.Debug("Auth Visitor failed")
return
}
var updateSql = "UPDATE reviewboard set customer_type=1, customer_id=? WHERE customer_type=2 AND customer_id=?"
log.Error("Sql: %s", updateSql)
_, err = dbHandler.Exec(updateSql, id, vid)
if err != nil {
log.Error("Sql: %s", updateSql)
log.Error("Update reviewboard owner failed: %v", err)
}
}
示例12: verifyRecover
func verifyRecover(req *restful.Request, resp *restful.Response) {
magic := req.PathParameter("recover_magic")
log.Debug("magic is %s", magic)
ret, id := dbVerifyRecover(magic)
if ret == http.StatusOK {
auth.AddCookie(req.Request, resp.ResponseWriter, strconv.FormatInt(id, 10))
http.Redirect(resp.ResponseWriter, req.Request, "/#!/mypassword", http.StatusFound)
} else {
resp.WriteErrorString(ret, http.StatusText(ret))
}
}
示例13: Decode
func Decode(c string) string {
key := []byte(sysMagicNumber)
ciphertext, _ := hex.DecodeString(c)
block, err := aes.NewCipher(key)
if err != nil {
log.Debug("%v", err)
return ""
}
// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
if len(ciphertext) < aes.BlockSize {
log.Debug("ciphertext too short")
return ""
}
iv := ciphertext[:aes.BlockSize]
ciphertext = ciphertext[aes.BlockSize:]
stream := cipher.NewCFBDecrypter(block, iv)
stream.XORKeyStream(ciphertext, ciphertext)
return fmt.Sprintf("%s\n", ciphertext)
}
示例14: dbSearchCustomersCount
func dbSearchCustomersCount(t string) (int64, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
querySql := fmt.Sprintf("select count(id) from user where type=1 and (name like '%%%s%%' or phone like '%%%s%%' or email like '%%%s%%') ", t, t, t)
var n sql.NullInt64
err = dbHandler.QueryRow(querySql).Scan(&n)
if err != nil {
log.Debug("sql : %s", querySql)
log.Error("DB query failed: %v", err)
return 0, http.StatusInternalServerError
}
return n.Int64, http.StatusOK
}
示例15: AuthHandler
func AuthHandler(r *http.Request, w http.ResponseWriter) (bool, string) {
s, err := CookieStore.Get(r, "ags-session")
if err != nil {
log.Debug("Cannot get session: %v", err)
return false, ""
}
if s.Values["id"] == nil || s.Values["time"] == nil || s.Values["magic"] == nil {
return false, ""
}
b := Check(s.Values["id"].(string), s.Values["time"].(string), s.Values["magic"].(string))
if b == true {
return true, s.Values["id"].(string)
} else {
return false, ""
}
}