本文整理匯總了Golang中github.com/featen/utils/log.Fatal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatal函數的具體用法?Golang Fatal怎麽用?Golang Fatal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fatal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: dbSearchProducts
func dbSearchProducts(t string, p int) ([]Product, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
offset := productPageLimit * (p - 1)
querySql := fmt.Sprintf("select id, nav_name, status, en_name, cover_photo, price from product WHERE en_name like '%%%s%%' order by id limit %d offset %d", t, productPageLimit, 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 products failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
products := make([]Product, 0)
for rows.Next() {
var productId, status sql.NullInt64
var navName, enName, coverPhoto sql.NullString
var price sql.NullFloat64
rows.Scan(&productId, &navName, &status, &enName, &coverPhoto, &price)
products = append(products, Product{productId.Int64, navName.String, status.Int64, enName.String, "", coverPhoto.String, "", "", price.Float64, 0, nil, nil, nil, nil, nil, nil})
}
return products, http.StatusOK
}
示例2: dbGetAllArticles
func dbGetAllArticles() ([]Article, int) {
log.Debug("get all articles")
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
stmt, err := dbHandler.Prepare("SELECT a.id, a.title, a.navname,a.cover_photo, a.intro, a.content, a.create_by_user_id, u.name, a.create_time, a.last_modify_time from article a, user u WHERE a.create_by_user_id=u.id ORDER BY a.id DESC")
if err != nil {
log.Error("%v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
log.Fatal("%v", err)
return nil, http.StatusInternalServerError
}
defer rows.Close()
allarticles := make([]Article, 10)
for rows.Next() {
var title, navname, cover_photo, intro, content, username sql.NullString
var articleid, userid sql.NullInt64
var createtime, modifytime time.Time
rows.Scan(&articleid, &title, &navname, &cover_photo, &intro, &content, &userid, &username, &createtime, &modifytime)
allarticles = append(allarticles, Article{strconv.FormatInt(articleid.Int64, 10), title.String, navname.String, intro.String, content.String, userid.Int64, username.String, "", createtime.Format(timeLayout), modifytime.Format(timeLayout), cover_photo.String})
}
rows.Close()
return allarticles, http.StatusOK
}
示例3: dbSearchEnquires
func dbSearchEnquires(t string, p int) ([]Enquire, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
offset := enquirePageLimit * (p - 1)
querySql := fmt.Sprintf("select id, status, customer_id, customer_name, subject, message, followup, create_time, last_modify_time from enquires where subject like '%%%s%%' or customer_name like '%%%s%%' order by id desc limit %d offset %d", t, t, enquirePageLimit, 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 products failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
es := make([]Enquire, 0)
for rows.Next() {
var enquire_id, status, customer_id sql.NullInt64
var customer_name, subject, message, followup sql.NullString
var create_time, last_modify_time time.Time
rows.Scan(&enquire_id, &status, &customer_id, &customer_name, &subject, &message, &followup, &create_time, &last_modify_time)
es = append(es, Enquire{auth.Encode(strconv.FormatInt(enquire_id.Int64, 10)), status.Int64, customer_id.Int64, customer_name.String, subject.String, message.String, 1, followup.String, nil, create_time.Format(timeLayout), last_modify_time.Format(timeLayout)})
}
return es, http.StatusOK
}
示例4: getConfigs
func getConfigs() {
b, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatal("Read test configuration file failed: ", err)
fmt.Println("read file failed")
}
err = json.Unmarshal(b, &sysConfig)
if err != nil {
log.Fatal("Unmarshal test configuration failed: ", err)
fmt.Println("unmarshal failed")
}
}
示例5: dbCreateArticle
func dbCreateArticle(article *Article) int {
log.Debug("try to create article %v", article)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
stmt, err := dbHandler.Prepare("INSERT INTO article (title, navname, cover_photo, intro, content, create_by_user_id, last_modify_time) VALUES (?,?,?,?,?,?, datetime('now','localtime','utc'))")
if err != nil {
log.Error("%v", err)
return http.StatusInternalServerError
}
defer stmt.Close()
r, err := stmt.Exec(article.Title, article.NavName, article.CoverPhoto, article.Intro, article.Content, article.UserId)
if err != nil {
log.Error("%v", err)
return http.StatusBadRequest
}
id, _ := r.LastInsertId()
article.Id = strconv.FormatInt(id, 10)
return http.StatusOK
}
示例6: saveConfigs
func saveConfigs() {
b, err := json.MarshalIndent(sysConfig, "", " ")
if err != nil {
log.Fatal("not be able to save configs")
}
ioutil.WriteFile(configFile, b, 0644)
}
示例7: dbGetReviewboardDetail
//usertype: 1:customer, 2:visitor
func dbGetReviewboardDetail(usertype int, userid int64) ([]ReviewboardProduct, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
querySql := "SELECT id, product_id, product_navname, product_name, cover_photo, price FROM reviewboard WHERE customer_type=? AND customer_id=? "
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(usertype, userid)
if err != nil {
log.Error("Query reviewboard detail failed, error : %v", err)
return nil, http.StatusNotFound
}
defer rows.Close()
ps := make([]ReviewboardProduct, 0)
for rows.Next() {
var id, product_id sql.NullInt64
var product_name, product_navname, cover_photo sql.NullString
var price sql.NullFloat64
rows.Scan(&id, &product_id, &product_navname, &product_name, &cover_photo, &price)
ps = append(ps, ReviewboardProduct{product_id.Int64, product_navname.String, product_name.String, cover_photo.String, price.Float64})
}
return ps, http.StatusOK
}
示例8: dbGetEnquireProducts
func dbGetEnquireProducts(id string) []ReviewboardProduct {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
querySql := "SELECT id, product_id, product_navname, product_name, cover_photo, price FROM enquire_product WHERE enquire_id=?"
stmt, err := dbHandler.Prepare(querySql)
if err != nil {
log.Debug("querySql: %s", querySql)
log.Error("Prepare failed: %v", err)
return nil
}
defer stmt.Close()
rows, err := stmt.Query(id)
if err != nil {
log.Error("Query enquire products failed, error : %v", err)
return nil
}
defer rows.Close()
ps := make([]ReviewboardProduct, 0)
for rows.Next() {
var id, product_id sql.NullInt64
var product_name, product_navname, cover_photo sql.NullString
var price sql.NullFloat64
rows.Scan(&id, &product_id, &product_navname, &product_name, &cover_photo, &price)
ps = append(ps, ReviewboardProduct{product_id.Int64, product_navname.String, product_name.String, cover_photo.String, price.Float64})
}
return ps
}
示例9: dbGetAllProducts
func dbGetAllProducts() ([]Product, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
var getSql = "SELECT count(*) FROM product ORDER BY id DESC "
var product_count sql.NullInt64
err = dbHandler.QueryRow(getSql).Scan(&product_count)
if err != nil {
if err == sql.ErrNoRows {
log.Info("sql error")
return nil, http.StatusInternalServerError
} else {
log.Error("DB query failed: %v", err)
return nil, http.StatusInternalServerError
}
}
if product_count.Int64 == 0 {
log.Error("No product in db")
return nil, http.StatusNotFound
}
stmt, err := dbHandler.Prepare("SELECT id, nav_name, status, en_name, cn_name, cover_photo, introduction, spec, price, discount FROM product ORDER BY id desc ")
if err != nil {
log.Error("Prepare all product failed : %v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
log.Fatal("Query all product failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
products := make([]Product, 0, product_count.Int64)
for rows.Next() {
var productId, status sql.NullInt64
var navName, enName, cnName, coverPhoto, introduction, spec sql.NullString
var price, discount sql.NullFloat64
rows.Scan(&productId, &navName, &status, &enName, &cnName, &coverPhoto, &introduction, &spec, &price, &discount)
products = append(products, Product{productId.Int64, navName.String, status.Int64, enName.String, cnName.String, coverPhoto.String, introduction.String, spec.String, price.Float64, discount.Float64, nil, nil, nil, nil, nil, nil})
}
return products, http.StatusOK
}
示例10: dbAddProduct
func dbAddProduct(p *Product) int {
log.Debug("try to add new product %v", p)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
if p.Photos != nil && len(p.Photos) > 0 {
p.CoverPhoto = p.Photos[0]
}
tx, err := dbHandler.Begin()
insertSql := "INSERT INTO product (nav_name, status, en_name, cn_name, cover_photo, introduction, spec, price, discount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
r, err := dbHandler.Exec(insertSql, p.NavName, p.Status, p.EnName, p.CnName, p.CoverPhoto, p.Introduction, p.Spec, p.Price, p.Discount)
if err != nil {
tx.Rollback()
log.Error("SQL: %s, err: %v", insertSql, err)
return http.StatusInternalServerError
}
id, _ := r.LastInsertId()
stmt, err := dbHandler.Prepare("INSERT INTO product_photo (product_id, url) VALUES (?,?)")
if err != nil {
tx.Rollback()
log.Error("prepare failed : %v", err)
return http.StatusInternalServerError
}
defer stmt.Close()
for _, url := range p.Photos {
_, err = stmt.Exec(id, url)
if err != nil {
tx.Rollback()
log.Error("insert product_photo failed: %v", err)
return http.StatusInternalServerError
}
}
stmt2, err := dbHandler.Prepare("INSERT INTO product_saleurl (product_id, url) VALUES (?,?)")
if err != nil {
tx.Rollback()
log.Error("prepare product_saleurl failed : %v", err)
return http.StatusInternalServerError
}
defer stmt2.Close()
for _, url := range p.SaleURL {
_, err = stmt2.Exec(id, url)
if err != nil {
tx.Rollback()
log.Error("insert product_photo failed: %v", err)
return http.StatusInternalServerError
}
}
tx.Commit()
return http.StatusOK
}
示例11: dbGenDataSaleAmount
func dbGenDataSaleAmount(reportData *ReportData) (*ReportData, int) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
var querySql string
switch reportData.Timeframe {
case "0":
querySql = "SELECT sum(paid_amount), date(create_time) from orders WHERE status>0 AND create_time >= (SELECT date(julianday(date('now'))-7)) AND create_time <= (SELECT date(julianday(date('now')))) group by date(create_time)"
case "1":
querySql = "SELECT sum(paid_amount), date(create_time) from orders WHERE status>0 AND create_time >= (SELECT date(julianday(date('now'))-30)) AND create_time <= (SELECT date(julianday(date('now')))) group by date(create_time)"
case "2":
querySql = "SELECT sum(paid_amount), date(create_time) from orders WHERE status>0 AND create_time >= (SELECT date(julianday(date('now'))-180)) AND create_time <= (SELECT date(julianday(date('now')))) group by date(create_time)"
case "3":
querySql = "SELECT sum(paid_amount), date(create_time) from orders WHERE status>0 group by date(create_time)"
}
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 orders failed, something changed on db schema? : %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
for rows.Next() {
//var id_count sql.NullInt64
var saleamount sql.NullFloat64
var date_day sql.NullString
rows.Scan(&saleamount, &date_day)
reportData.Xvalues = append(reportData.Xvalues, date_day.String)
reportData.Yvalues = append(reportData.Yvalues, saleamount.Float64)
}
return reportData, http.StatusOK
}
示例12: dbGetPageArticles
func dbGetPageArticles(pagenumber int64) ([]Article, int) {
log.Debug("get page articles for %d", pagenumber)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
pageArticlesLimit, err := strconv.ParseInt(config.GetValue("DealsPerPage"), 10, 64)
if err != nil {
return nil, http.StatusInternalServerError
}
if pagenumber <= 0 {
return nil, http.StatusBadRequest
}
offset := (pagenumber - 1) * pageArticlesLimit
stmt, err := dbHandler.Prepare("SELECT a.id, a.title, a.navname, a.cover_photo, a.intro, a.create_by_user_id, u.name, a.create_time, a.last_modify_time from article a, user u WHERE a.create_by_user_id=u.id ORDER BY a.id DESC limit ? offset ?")
if err != nil {
log.Error("%v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query(pageArticlesLimit, offset)
if err != nil {
log.Fatal("%v", err)
return nil, http.StatusInternalServerError
}
defer rows.Close()
allarticles := make([]Article, 0)
for rows.Next() {
var title, navname, cover_photo, intro, username sql.NullString
var articleid, userid sql.NullInt64
var createtime, modifytime time.Time
rows.Scan(&articleid, &title, &navname, &cover_photo, &intro, &userid, &username, &createtime, &modifytime)
allarticles = append(allarticles, Article{strconv.FormatInt(articleid.Int64, 10), title.String, navname.String, intro.String, "", userid.Int64, username.String, "", createtime.Format(timeLayout), modifytime.Format(timeLayout), cover_photo.String})
}
rows.Close()
return allarticles, http.StatusOK
}
示例13: addAdminUser
func addAdminUser() {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
fmt.Println("dbHandler failed", err)
}
defer dbHandler.Close()
addAdminSql := fmt.Sprintf("INSERT INTO user (name, type, pass, email) VALUES ('%s', 0, '%s', '%s')", config.GetValue("AdminName"), config.GetValue("AdminPassword"), config.GetValue("AdminEmail"))
dbHandler.Exec(addAdminSql)
}
示例14: updateAdminUser
func updateAdminUser() {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
fmt.Println("dbHandler failed", err)
}
defer dbHandler.Close()
updateAdminSql := fmt.Sprintf("UPDATE user set name=?, pass=?, email=? WHERE type=0")
dbHandler.Exec(updateAdminSql, config.GetValue("AdminName"), config.GetValue("AdminPassword"), config.GetValue("AdminEmail"))
}
示例15: dbGetPageDeals
func dbGetPageDeals(pagenumber int64) ([]Product, int) {
log.Debug("get page deals for %d", pagenumber)
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
pageDealsLimit, err := strconv.ParseInt(config.GetValue("DealsPerPage"), 10, 64)
if err != nil {
return nil, http.StatusInternalServerError
}
if pagenumber <= 0 {
return nil, http.StatusBadRequest
}
//show latest deals only
//offset := (pagenumber - 1) * pageDealsLimit
offset := 0
stmt, err := dbHandler.Prepare("SELECT id, nav_name, status, en_name, cn_name, cover_photo, price, discount FROM product WHERE status!=0 ORDER BY id desc limit ? offset ?")
if err != nil {
log.Error("Prepare to get page deal failed : %v", err)
return nil, http.StatusInternalServerError
}
defer stmt.Close()
rows, err := stmt.Query(pageDealsLimit, offset)
if err != nil {
log.Fatal("Query page deals failed: %v ", err)
return nil, http.StatusNotFound
}
defer rows.Close()
products := make([]Product, 0)
for rows.Next() {
var productId, status sql.NullInt64
var navName, enName, cnName, coverPhoto sql.NullString
var price, discount sql.NullFloat64
rows.Scan(&productId, &navName, &status, &enName, &cnName, &coverPhoto, &price, &discount)
products = append(products, Product{productId.Int64, navName.String, status.Int64, enName.String, cnName.String, coverPhoto.String, "", "", price.Float64, discount.Float64, nil, nil, nil, nil, nil, nil})
}
return products, http.StatusOK
}