diff --git a/controllers/admin/account.go b/controllers/admin/account.go index 778ceba..56e5861 100644 --- a/controllers/admin/account.go +++ b/controllers/admin/account.go @@ -1,9 +1,10 @@ package admin import ( - "github.com/lisijie/goblog/models" "strconv" "strings" + + "github.com/lisijie/goblog/models" ) type AccountController struct { @@ -30,9 +31,9 @@ func (this *AccountController) Login() { user.Update() authkey := models.Md5([]byte(this.getClientIp() + "|" + user.Password)) if remember == "yes" { - this.Ctx.SetCookie("auth", strconv.FormatInt(user.Id, 10)+"|"+authkey, 7*86400) + this.Ctx.SetCookie("auth", strconv.Itoa(user.Id)+"|"+authkey, 7*86400) } else { - this.Ctx.SetCookie("auth", strconv.FormatInt(user.Id, 10)+"|"+authkey) + this.Ctx.SetCookie("auth", strconv.Itoa(user.Id)+"|"+authkey) } this.Redirect("/admin", 302) diff --git a/controllers/admin/article.go b/controllers/admin/article.go index 3f4be7e..937dbe7 100644 --- a/controllers/admin/article.go +++ b/controllers/admin/article.go @@ -2,12 +2,13 @@ package admin import ( "fmt" - "github.com/astaxie/beego/orm" - "github.com/lisijie/goblog/models" "os" "strconv" "strings" "time" + + "github.com/astaxie/beego/orm" + "github.com/lisijie/goblog/models" ) type ArticleController struct { @@ -17,10 +18,10 @@ type ArticleController struct { //管理 func (this *ArticleController) List() { var ( - page int64 - pagesize int64 = 10 - status int64 - offset int64 + page int + pagesize int = 10 + status int + offset int list []*models.Post post models.Post searchtype string @@ -58,7 +59,7 @@ func (this *ArticleController) List() { this.Data["status"] = status this.Data["count"] = count this.Data["list"] = list - this.Data["pagebar"] = models.NewPager(page, count, pagesize, fmt.Sprintf("/admin/article/list?status=%d&searchtype=%s&keyword=%s", status, searchtype, keyword), true).ToString() + this.Data["pagebar"] = models.NewPager(page, int(count), pagesize, fmt.Sprintf("/admin/article/list?status=%d&searchtype=%s&keyword=%s", status, searchtype, keyword), true).ToString() this.display() } @@ -84,14 +85,14 @@ func (this *ArticleController) Edit() { //保存 func (this *ArticleController) Save() { var ( - id int64 = 0 + id int = 0 title string = strings.TrimSpace(this.GetString("title")) content string = this.GetString("content") tags string = strings.TrimSpace(this.GetString("tags")) urlname string = strings.TrimSpace(this.GetString("urlname")) color string = strings.TrimSpace(this.GetString("color")) timestr string = strings.TrimSpace(this.GetString("posttime")) - status int64 = 0 + status int = 0 istop int8 = 0 urltype int8 = 0 post models.Post @@ -205,10 +206,10 @@ func (this *ArticleController) Batch() { ids := this.GetStrings("ids[]") op := this.GetString("op") - idarr := make([]int64, 0) + idarr := make([]int, 0) for _, v := range ids { if id, _ := strconv.Atoi(v); id > 0 { - idarr = append(idarr, int64(id)) + idarr = append(idarr, int(id)) } } diff --git a/controllers/admin/base.go b/controllers/admin/base.go index ceb0597..1585b45 100644 --- a/controllers/admin/base.go +++ b/controllers/admin/base.go @@ -1,16 +1,17 @@ package admin import ( - "github.com/astaxie/beego" - "github.com/lisijie/goblog/models" "strconv" "strings" "time" + + "github.com/astaxie/beego" + "github.com/lisijie/goblog/models" ) type baseController struct { beego.Controller - userid int64 + userid int username string moduleName string controllerName string @@ -34,7 +35,7 @@ func (this *baseController) auth() { arr := strings.Split(this.Ctx.GetCookie("auth"), "|") if len(arr) == 2 { idstr, password := arr[0], arr[1] - userid, _ := strconv.ParseInt(idstr, 10, 0) + userid, _ := strconv.Atoi(idstr) if userid > 0 { var user models.User user.Id = userid diff --git a/controllers/admin/tag.go b/controllers/admin/tag.go index 9419535..ca724e0 100644 --- a/controllers/admin/tag.go +++ b/controllers/admin/tag.go @@ -1,9 +1,10 @@ package admin import ( - "github.com/lisijie/goblog/models" "strconv" "strings" + + "github.com/lisijie/goblog/models" ) type TagController struct { @@ -22,8 +23,8 @@ func (this *TagController) Index() { //标签列表 func (this *TagController) list() { - var page int64 - var pagesize int64 = 10 + var page int + var pagesize int = 10 var list []*models.Tag var tag models.Tag @@ -39,7 +40,7 @@ func (this *TagController) list() { this.Data["count"] = count this.Data["list"] = list - this.Data["pagebar"] = models.NewPager(page, count, pagesize, "/admin/tag", true).ToString() + this.Data["pagebar"] = models.NewPager(page, int(count), pagesize, "/admin/tag", true).ToString() this.display("tag_list") } @@ -48,10 +49,10 @@ func (this *TagController) batch() { ids := this.GetStrings("ids[]") op := this.GetString("op") - idarr := make([]int64, 0) + idarr := make([]int, 0) for _, v := range ids { if id, _ := strconv.Atoi(v); id > 0 { - idarr = append(idarr, int64(id)) + idarr = append(idarr, int(id)) } } diff --git a/controllers/admin/user.go b/controllers/admin/user.go index fa5d057..8b85beb 100644 --- a/controllers/admin/user.go +++ b/controllers/admin/user.go @@ -1,9 +1,10 @@ package admin import ( + "strings" + "github.com/astaxie/beego/validation" "github.com/lisijie/goblog/models" - "strings" ) type UserController struct { @@ -12,8 +13,8 @@ type UserController struct { //用户列表 func (this *UserController) List() { - var page int64 - var pagesize int64 = 10 + var page int + var pagesize int = 10 var list []*models.User var user models.User @@ -29,7 +30,7 @@ func (this *UserController) List() { this.Data["count"] = count this.Data["list"] = list - this.Data["pagebar"] = models.NewPager(page, count, pagesize, "/admin/user/list", true).ToString() + this.Data["pagebar"] = models.NewPager(page, int(count), pagesize, "/admin/user/list", true).ToString() this.display() } diff --git a/controllers/blog/main.go b/controllers/blog/main.go index c01061e..4349684 100644 --- a/controllers/blog/main.go +++ b/controllers/blog/main.go @@ -1,9 +1,10 @@ package blog import ( - "github.com/lisijie/goblog/models" "strconv" "strings" + + "github.com/lisijie/goblog/models" ) type MainController struct { @@ -35,7 +36,7 @@ func (this *MainController) Index() { this.Data["count"] = count this.Data["list"] = list - this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "").ToString() + this.Data["pagebar"] = models.NewPager(int(page), int(count), int(pagesize), "").ToString() this.setHeadMetas() this.display("index") } @@ -53,7 +54,7 @@ func (this *MainController) Show() { err = post.Read("urlname") } else { id, _ := strconv.Atoi(this.Ctx.Input.Param(":id")) - post.Id = int64(id) + post.Id = int(id) err = post.Read() } if err != nil || post.Status != 0 { @@ -76,7 +77,7 @@ func (this *MainController) Archives() { page int pagesize int err error - count int64 + count int result map[string][]*models.Post ) @@ -92,7 +93,8 @@ func (this *MainController) Archives() { query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0) - count, _ = query.Count() + c, _ := query.Count() + count = int(c) result = make(map[string][]*models.Post) if count > 0 { var list []*models.Post @@ -109,7 +111,7 @@ func (this *MainController) Archives() { this.Data["page"] = page this.Data["count"] = count this.Data["pagesize"] = pagesize - this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "/archives").ToString() + this.Data["pagebar"] = models.NewPager(int(page), int(count), int(pagesize), "/archives").ToString() this.Data["result"] = result this.setHeadMetas("归档") @@ -123,7 +125,7 @@ func (this *MainController) Category() { pagesize int name string err error - count int64 + count int result map[string][]*models.Post ) name = this.Ctx.Input.Param(":name") @@ -145,12 +147,13 @@ func (this *MainController) Category() { } query := tagpost.Query().Filter("tagid", tag.Id).Filter("poststatus", 0) - count, _ = query.Count() + c, _ := query.Count() + count = int(c) result = make(map[string][]*models.Post) if count > 0 { var tp []*models.TagPost var list []*models.Post - var pids []int64 = make([]int64, 0) + var pids []int = make([]int, 0) query.OrderBy("-posttime").Limit(pagesize, (page-1)*pagesize).All(&tp) for _, v := range tp { @@ -173,7 +176,7 @@ func (this *MainController) Category() { this.Data["pagesize"] = pagesize this.Data["count"] = count this.Data["result"] = result - this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), tag.Link()).ToString() + this.Data["pagebar"] = models.NewPager(page, int(count), pagesize, tag.Link()).ToString() this.setHeadMetas(tag.Name, tag.Name, tag.Name) this.display("category") diff --git a/goblog b/goblog new file mode 100755 index 0000000..26f3677 Binary files /dev/null and b/goblog differ diff --git a/models/pager.go b/models/pager.go index 7882369..00a475b 100644 --- a/models/pager.go +++ b/models/pager.go @@ -8,15 +8,15 @@ import ( ) type Pager struct { - Page int64 - Totalnum int64 - Pagesize int64 + Page int + Totalnum int + Pagesize int urlpath string urlquery string nopath bool } -func NewPager(page, totalnum, pagesize int64, url string, nopath ...bool) *Pager { +func NewPager(page, totalnum, pagesize int, url string, nopath ...bool) *Pager { p := new(Pager) p.Page = page p.Totalnum = totalnum @@ -39,7 +39,7 @@ func NewPager(page, totalnum, pagesize int64, url string, nopath ...bool) *Pager return p } -func (this *Pager) url(page int64) string { +func (this *Pager) url(page int) string { if this.nopath { //不使用目录形式 if this.urlquery != "" { return fmt.Sprintf("%s%s&page=%d", this.urlpath, this.urlquery, page) @@ -57,12 +57,12 @@ func (this *Pager) ToString() string { } var buf bytes.Buffer - var from, to, linknum, offset, totalpage int64 + var from, to, linknum, offset, totalpage int offset = 5 linknum = 10 - totalpage = int64(math.Ceil(float64(this.Totalnum) / float64(this.Pagesize))) + totalpage = int(math.Ceil(float64(this.Totalnum) / float64(this.Pagesize))) if totalpage < linknum { from = 1 diff --git a/models/post.go b/models/post.go index 9faf1ec..8a7aa57 100644 --- a/models/post.go +++ b/models/post.go @@ -3,14 +3,15 @@ package models import ( "bytes" "fmt" - "github.com/astaxie/beego/orm" "strings" "time" + + "github.com/astaxie/beego/orm" ) type Post struct { - Id int64 - Userid int64 `orm:"index"` + Id int + Userid int `orm:"index"` Author string `orm:"size(15)"` Title string `orm:"size(100)"` Color string `orm:"size(7)"` @@ -19,7 +20,7 @@ type Post struct { Content string `orm:"type(text)"` Tags string `orm:"size(100)"` Posttime time.Time `orm:"type(datetime);index"` - Views int64 + Views int Status int8 Updated time.Time `orm:"type(datetime)"` Istop int8 diff --git a/models/tag.go b/models/tag.go index 6bda590..cc51ec1 100644 --- a/models/tag.go +++ b/models/tag.go @@ -2,16 +2,17 @@ package models import ( "fmt" - "github.com/astaxie/beego/orm" "strconv" "strings" + + "github.com/astaxie/beego/orm" ) //标签表 type Tag struct { - Id int64 + Id int Name string `orm:"size(20);index"` - Count int64 + Count int } func (m *Tag) TableName() string { @@ -47,7 +48,7 @@ func (m *Tag) Delete() error { if len(list) > 0 { ids := make([]string, 0, len(list)) for _, v := range list { - ids = append(ids, strconv.FormatInt(v.Postid, 10)) + ids = append(ids, strconv.Itoa(v.Postid)) } orm.NewOrm().Raw("UPDATE "+table+" SET tags = REPLACE(tags, ?,',') WHERE id IN ("+strings.Join(ids, ",")+")", ","+m.Name+",").Exec() new(TagPost).Query().Filter("tagid", m.Id).Delete() @@ -70,7 +71,8 @@ func (m *Tag) Link() string { //更新统计 func (m *Tag) UpCount() { - m.Count, _ = new(TagPost).Query().Filter("tagid", m.Id).Count() + count, _ := new(TagPost).Query().Filter("tagid", m.Id).Count() + m.Count = int(count) m.Update("count") } @@ -82,7 +84,7 @@ func (m *Tag) MergeTo(to *Tag) { if len(list) > 0 { ids := make([]string, 0, len(list)) for _, v := range list { - ids = append(ids, strconv.FormatInt(v.Postid, 10)) + ids = append(ids, strconv.Itoa(v.Postid)) } tp.Query().Filter("tagid", m.Id).Update(orm.Params{"tagid": to.Id}) orm.NewOrm().Raw("UPDATE "+new(Post).TableName()+" SET tags = REPLACE(tags, ?, ?) WHERE id IN ("+strings.Join(ids, ",")+")", ","+m.Name+",", ","+to.Name+",").Exec() diff --git a/models/tagpost.go b/models/tagpost.go index 8b86ba6..cf6a760 100644 --- a/models/tagpost.go +++ b/models/tagpost.go @@ -1,15 +1,16 @@ package models import ( - "github.com/astaxie/beego/orm" "time" + + "github.com/astaxie/beego/orm" ) //标签内容关系表 type TagPost struct { - Id int64 - Tagid int64 `orm:"index"` - Postid int64 + Id int + Tagid int `orm:"index"` + Postid int Poststatus int8 Posttime time.Time } diff --git a/models/user.go b/models/user.go index f2ce82a..8dfc050 100644 --- a/models/user.go +++ b/models/user.go @@ -1,18 +1,19 @@ package models import ( - "github.com/astaxie/beego/orm" "time" + + "github.com/astaxie/beego/orm" ) //用户表模型 type User struct { - Id int64 + Id int Username string `orm:"unique;size(15)"` Password string `orm:"size(32)"` Email string `orm:"size(50)"` Lastlogin time.Time `orm:"auto_now_add;type(datetime)"` - Logincount int64 + Logincount int Lastip string `orm:"size(32)"` Authkey string `orm:"size(10)"` Active int8