本文整理匯總了Golang中github.com/featen/ags/service/config.GetValue函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetValue函數的具體用法?Golang GetValue怎麽用?Golang GetValue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetValue函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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"))
}
示例2: 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
}
示例3: 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
}
示例4: dbVerifyRecover
func dbVerifyRecover(magic string) (int, int64) {
dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
if err != nil {
log.Fatal("%v", err)
}
defer dbHandler.Close()
var getSql = "SELECT u.id FROM user u, user_recover_pass urp WHERE u.email=urp.email AND urp.magic=?"
var value sql.NullInt64
err = dbHandler.QueryRow(getSql, magic).Scan(&value)
if err != nil {
if err == sql.ErrNoRows {
log.Info("No magic found for %s", magic)
return http.StatusNotFound, 0
} else {
log.Error("DB query failed: %v", err)
return http.StatusInternalServerError, 0
}
}
var delSql = "DELETE from user_recover_pass WHERE magic=?"
_, err = dbHandler.Exec(delSql, magic)
if err != nil {
log.Error("SQL: %s", delSql)
return http.StatusInternalServerError, 0
}
return http.StatusOK, value.Int64
}
示例5: 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
}
示例6: 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
}
示例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: 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
}
示例10: 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
}
示例11: 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
}
示例12: 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
}
示例13: 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
}
示例14: 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
}
示例15: 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)
}