Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions controllers/admin/account.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package admin

import (
"github.com/lisijie/goblog/models"
"strconv"
"strings"

"github.com/lisijie/goblog/models"
)

type AccountController struct {
Expand All @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions controllers/admin/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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()
}

Expand All @@ -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
Expand Down Expand Up @@ -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))
}
}

Expand Down
9 changes: 5 additions & 4 deletions controllers/admin/base.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions controllers/admin/tag.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package admin

import (
"github.com/lisijie/goblog/models"
"strconv"
"strings"

"github.com/lisijie/goblog/models"
)

type TagController struct {
Expand All @@ -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

Expand All @@ -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")
}

Expand All @@ -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))
}
}

Expand Down
9 changes: 5 additions & 4 deletions controllers/admin/user.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package admin

import (
"strings"

"github.com/astaxie/beego/validation"
"github.com/lisijie/goblog/models"
"strings"
)

type UserController struct {
Expand All @@ -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

Expand All @@ -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()
}

Expand Down
23 changes: 13 additions & 10 deletions controllers/blog/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package blog

import (
"github.com/lisijie/goblog/models"
"strconv"
"strings"

"github.com/lisijie/goblog/models"
)

type MainController struct {
Expand Down Expand Up @@ -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")
}
Expand All @@ -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 {
Expand All @@ -76,7 +77,7 @@ func (this *MainController) Archives() {
page int
pagesize int
err error
count int64
count int
result map[string][]*models.Post
)

Expand All @@ -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
Expand All @@ -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("归档")
Expand All @@ -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")
Expand All @@ -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 {
Expand All @@ -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")
Expand Down
Binary file added goblog
Binary file not shown.
14 changes: 7 additions & 7 deletions models/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions models/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand All @@ -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
Expand Down
Loading