Commit c1cf6424 by usual2970

修改商品

parent 42a9d20a
package: github.com/usual2970/util
import:
- package: github.com/PuerkitoBio/goquery
version: v1.0.1
- package: github.com/astaxie/beego
version: v1.7.2
subpackages:
- logs
- package: github.com/go-sql-driver/mysql
version: v1.3
- package: github.com/gorilla/websocket
version: v1.0.0
- package: github.com/hu17889/go_spider
version: v1.0
subpackages:
- core/common/com_interfaces
- core/common/page
- core/common/page_items
- core/common/request
- core/spider
- package: github.com/mcuadros/go-version
- package: github.com/pquerna/ffjson
subpackages:
- ffjson
- package: github.com/upyun/go-sdk
version: v2.0.0
subpackages:
- upyun
testImport:
- package: github.com/smartystreets/goconvey
version: 1.6.2
subpackages:
- convey
appname = service
httpport = 8082
httpport = 8080
runmode = dev
copyrequestbody = true
autorender=true
......@@ -7,3 +7,13 @@ autorender=true
upusername=staticydl
uppassword=ydl12345com
upbucket=staticydl
dbuser = root
dbpass = 123456Aa
dburl = 127.0.0.1
dbname = qqxinlin
dbport = 3306
db_max_idle_conn = 30
db_max_open_conn = 200
package controllers
import (
"github.com/astaxie/beego"
"fmt"
"github.com/usual2970/util/service/models"
)
type AskController struct {
beego.Controller
}
func (c *AskController) Index() {
asks,err:=models.GetAllAsk(nil,nil,[]string{"id"},[]string{"desc"},int64(0),int64(20))
if err!=nil{
fmt.Println(1234)
return
}
c.Data["asks"]=asks
c.TplName="ask_index.tpl"
}
func (c *AskController) View() {
}
......@@ -3,9 +3,37 @@ package main
import (
_ "github.com/usual2970/util/service/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
initGlobal()
beego.Run()
}
func initGlobal(){
Cfg := beego.AppConfig
//初始化数据库连接
dbUser := Cfg.String("dbuser")
dbPass := Cfg.String("dbpass")
dbHost := Cfg.String("dburl")
dbPort := Cfg.String("dbport")
dbName := Cfg.String("dbname")
maxIdleConn, _ := Cfg.Int("db_max_idle_conn")
maxOpenConn, _ := Cfg.Int("db_max_open_conn")
dbLink := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPass, dbHost, dbPort, dbName) + "&loc=Asia%2FChongqing&allowOldPasswords=1"
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", dbLink, maxIdleConn, maxOpenConn)
}
\ No newline at end of file
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"github.com/astaxie/beego/orm"
)
type Answer struct {
Id int64 `orm:"pk"`
Content string `orm:"longtext"`
AskOriginId string `orm:"size(128)"`
ExpertName string `orm:"size(128)"`
ExpertTitle string `orm:"size(128)"`
ExpertHead string `orm:"size(128)"`
AnswerTime string `orm:"size(128)"`
}
func init() {
orm.RegisterModel(new(Answer))
}
// AddAnswer insert a new Answer into database and returns
// last inserted Id on success.
func AddAnswer(m *Answer) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAnswerById retrieves Answer by Id. Returns error if
// Id doesn't exist
func GetAnswerById(id int64) (v *Answer, err error) {
o := orm.NewOrm()
v = &Answer{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// GetAllAnswer retrieves all Answer matches certain condition. Returns empty list if
// no records exist
func GetAllAnswer(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Answer))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
qs = qs.Filter(k, v)
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Answer
qs = qs.OrderBy(sortFields...)
if _, err := qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAnswer updates Answer by Id and returns error if
// the record to be updated doesn't exist
func UpdateAnswerById(m *Answer) (err error) {
o := orm.NewOrm()
v := Answer{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAnswer deletes Answer by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAnswer(id int64) (err error) {
o := orm.NewOrm()
v := Answer{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&Answer{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"github.com/astaxie/beego/orm"
)
type Ask struct {
Id int64 `orm:"pk"`
OriginId string `orm:"size(128)"`
OriginUrl string `orm:"size(128)"`
OriginUid string `orm:"size(128)"`
Source string `orm:"size(128)"`
Title string `orm:"size(128)"`
Content string `orm:"longtext"`
AnswerNum int
NickName string `orm:"size(128)"`
Gender string `orm:"size(128)"`
EducationBackground string `orm:"size(128)"`
Age string `orm:"size(128)"`
Area string `orm:"size(128)"`
Head string `orm:"size(128)"`
Marriage string `orm:"size(128)"`
CreateTime string `orm:"size(128)"`
}
func init() {
orm.RegisterModel(new(Ask))
}
// AddAsk insert a new Ask into database and returns
// last inserted Id on success.
func AddAsk(m *Ask) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAskById retrieves Ask by Id. Returns error if
// Id doesn't exist
func GetAskById(id int64) (v *Ask, err error) {
o := orm.NewOrm()
v = &Ask{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// GetAllAsk retrieves all Ask matches certain condition. Returns empty list if
// no records exist
func GetAllAsk(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Ask))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
qs = qs.Filter(k, v)
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Ask
qs = qs.OrderBy(sortFields...)
if _, err := qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAsk updates Ask by Id and returns error if
// the record to be updated doesn't exist
func UpdateAskById(m *Ask) (err error) {
o := orm.NewOrm()
v := Ask{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAsk deletes Ask by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAsk(id int64) (err error) {
o := orm.NewOrm()
v := Ask{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&Ask{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
......@@ -11,4 +11,6 @@ func init() {
beego.Router("/im",&controllers.MainController{})
beego.AutoRouter(&controllers.TelController{})
beego.AutoRouter(&controllers.GitController{})
beego.Router("/ask", &controllers.AskController{},"*:Index")
beego.Router("/ask/:id:int", &controllers.AskController{},"*:View")
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<div class="copyright">
<p>©2013 头条网 toutiao.com 京ICP证12025439号 京公网安备11010802012471号</p>
<p>网络文化经营许可证 跟帖评论自律管理承诺书 违法和不良信息举报电话:010-58733394 公司名称:北京字节跳动科技有限公司/北京字节跳动网络技术有限公司</p>
</div>
<script src="/static/js/bootstrap.js"></script>
</body></html>
\ No newline at end of file
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
<!--360浏览器支持启动webkit内核-->
<meta name="renderer" content="webkit">
<title>QQ心理</title>
<link rel="stylesheet" href="/static/css/bootstrap.css">
</head>
<body data-log-from="Index">
<div id="wrapper" data-log-from=""><div class="index-header" id="paglet-index-header" data-log-from="!Nav">
<div class="index-header-wrapper"><div id="pagelet-midbar" class="header-index">
<div class="midbar-inner" data-node="midbarInner">
<div class="inner clearfix">
<div class="logo-box">
<a class="logo-link" href="/" data-log="Visit_Index|From_logo">
<img class="logo" src="//s3.pstatp.com/wenda/wenda_web/static/style/image/logo_97cede9.png" alt="">
</a>
</div>
<div class="search-box" event-binded="1"><div data-node="searchBox" class="widget-search-input">
<form action="/search/" method="get" data-node="searchForm" target="_blank">
<div class="input-group clearfix">
<input autocomplete="off" ga_event="nav_search_input" data-node="searchInput" name="keyword" type="text" placeholder="搜索你感兴趣的问题" value="">
<div class="btn-submit">
<button ga_event="nav_search" type="submit" href="javascript:;">
<i class="icon iconfont-umeditor icon-search icon-large"></i>
</button>
</div>
</div>
</form>
<div class="layer" data-node="sug-layer">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment