Skip to content

Commit

Permalink
🏗️ ID 使用 uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 2, 2018
1 parent 50fc6a3 commit 5bbe5f7
Show file tree
Hide file tree
Showing 43 changed files with 155 additions and 151 deletions.
2 changes: 1 addition & 1 deletion cache/settingcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (cache *settingCache) Put(setting *model.Setting) {
}
}

func (cache *settingCache) Get(category, name string, blogID uint) *model.Setting {
func (cache *settingCache) Get(category, name string, blogID uint64) *model.Setting {
ret, err := cache.categoryNameHolder.Get(fmt.Sprintf("%s-%s-%d", category, name, blogID))
if nil != err && gcache.KeyNotFoundError != err {
logger.Errorf("get setting [name=%s, category=%s, blogID=%d] from cache failed: %s", category, name, blogID, err)
Expand Down
2 changes: 1 addition & 1 deletion cache/usercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (cache *userCache) Put(user *model.User) {
}
}

func (cache *userCache) Get(id uint) *model.User {
func (cache *userCache) Get(id uint64) *model.User {
ret, err := cache.idHolder.Get(id)
if nil != err && gcache.KeyNotFoundError != err {
logger.Errorf("get user [id=%d] from cache failed: %s", id, err)
Expand Down
12 changes: 6 additions & 6 deletions controller/blogmidware.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func fillCommon(c *gin.Context) {
c.Set("dataModel", dataModel)
}

func fillMostUseCategories(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
func fillMostUseCategories(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint64) {
categories := service.Category.GetCategories(math.MaxInt8, blogID)
var themeCategories []*model.ThemeCategory
for _, category := range categories {
Expand All @@ -156,7 +156,7 @@ func fillMostUseCategories(settingMap *map[string]interface{}, dataModel *DataMo
(*dataModel)["MostUseCategories"] = themeCategories
}

func fillMostUseTags(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
func fillMostUseTags(settingMap *map[string]interface{}, dataModel *DataModel, blogID uint64) {
tagSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostUseTagListSize].(string))
if nil != err {
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostUseTagListSize,
Expand All @@ -175,7 +175,7 @@ func fillMostUseTags(settingMap *map[string]interface{}, dataModel *DataModel, b
(*dataModel)["MostUseTags"] = themeTags
}

func fillMostViewArticles(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
func fillMostViewArticles(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint64) {
mostViewArticleSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostViewArticleListSize].(string))
if nil != err {
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostViewArticleListSize,
Expand Down Expand Up @@ -208,7 +208,7 @@ func fillMostViewArticles(c *gin.Context, settingMap *map[string]interface{}, da
(*dataModel)["MostViewArticles"] = themeMostViewArticles
}

func fillRecentComments(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
func fillRecentComments(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint64) {
recentCommentSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceRecentCommentListSize].(string))
if nil != err {
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceRecentCommentListSize,
Expand Down Expand Up @@ -246,7 +246,7 @@ func fillRecentComments(c *gin.Context, settingMap *map[string]interface{}, data
(*dataModel)["RecentComments"] = themeRecentComments
}

func fillMostCommentArticles(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint) {
func fillMostCommentArticles(c *gin.Context, settingMap *map[string]interface{}, dataModel *DataModel, blogID uint64) {
mostCommentArticleSize, err := strconv.Atoi((*settingMap)[model.SettingNamePreferenceMostCommentArticleListSize].(string))
if nil != err {
logger.Errorf("setting [%s] should be an integer, actual is [%v]", model.SettingNamePreferenceMostCommentArticleListSize,
Expand Down Expand Up @@ -285,7 +285,7 @@ func getBlogURL(c *gin.Context) string {
return dataModel["Setting"].(map[string]interface{})[model.SettingNameBasicBlogURL].(string)
}

func getBlogID(c *gin.Context) uint {
func getBlogID(c *gin.Context) uint64 {
userBlogVal, _ := c.Get("userBlog")

return userBlogVal.(*service.UserBlog).ID
Expand Down
4 changes: 2 additions & 2 deletions controller/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func getRepliesAction(c *gin.Context) {
blogID := getBlogID(c)
parentCmtIDArg := strings.SplitAfter(c.Request.URL.Path, util.PathComments+"/")[1]
parentCmtIDArg = strings.Split(parentCmtIDArg, "/replies")[0]
parentCmtID, _ := strconv.Atoi(parentCmtIDArg)
parentCmtID, _ := strconv.ParseUint(parentCmtIDArg, 10, 64)

replyComments := service.Comment.GetReplies(uint(parentCmtID), blogID)
replyComments := service.Comment.GetReplies(parentCmtID, blogID)
var replies []*model.ThemeReply
for _, replyComment := range replyComments {
commentAuthor := service.User.GetUser(replyComment.AuthorID)
Expand Down
14 changes: 7 additions & 7 deletions controller/console/articlectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ func GetArticleAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1

return
}

data := service.Article.ConsoleGetArticle(uint(id))
data := service.Article.ConsoleGetArticle(uint64(id))
if nil == data {
result.Code = -1

Expand Down Expand Up @@ -149,15 +149,15 @@ func RemoveArticleAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

if err := service.Article.RemoveArticle(uint(id)); nil != err {
if err := service.Article.RemoveArticle(uint64(id)); nil != err {
result.Code = -1
result.Msg = err.Error()
}
Expand All @@ -177,7 +177,7 @@ func RemoveArticlesAction(c *gin.Context) {

ids := arg["ids"].([]interface{})
for _, id := range ids {
if err := service.Article.RemoveArticle(uint(id.(float64))); nil != err {
if err := service.Article.RemoveArticle(uint64(id.(float64))); nil != err {
logger.Errorf("remove article failed: " + err.Error())
}
}
Expand All @@ -188,15 +188,15 @@ func UpdateArticleAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

article := &model.Article{Model: model.Model{ID: uint(id)}}
article := &model.Article{Model: model.Model{ID: uint64(id)}}
if err := c.BindJSON(article); nil != err {
result.Code = -1
result.Msg = "parses update article request failed"
Expand Down
6 changes: 3 additions & 3 deletions controller/console/blogctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func BlogSwitchAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
blogID, err := strconv.Atoi(idArg)
blogID, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1

Expand All @@ -52,7 +52,7 @@ func BlogSwitchAction(c *gin.Context) {

role := -1
for _, userBlog := range userBlogs {
if userBlog.ID == uint(blogID) {
if userBlog.ID == uint64(blogID) {
role = userBlog.UserRole

break
Expand All @@ -69,7 +69,7 @@ func BlogSwitchAction(c *gin.Context) {
result.Data = role

session.URole = role
session.BID = uint(blogID)
session.BID = uint64(blogID)
session.Save(c)
}

Expand Down
12 changes: 6 additions & 6 deletions controller/console/categoryctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func UpdateCategoryAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

category := &model.Category{Model: model.Model{ID: uint(id)}}
category := &model.Category{Model: model.Model{ID: uint64(id)}}
if err := c.BindJSON(category); nil != err {
result.Code = -1
result.Msg = "parses update category request failed"
Expand All @@ -61,15 +61,15 @@ func GetCategoryAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

data := service.Category.ConsoleGetCategory(uint(id))
data := service.Category.ConsoleGetCategory(id)
if nil == data {
result.Code = -1

Expand Down Expand Up @@ -131,15 +131,15 @@ func RemoveCategoryAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

if err := service.Category.RemoveCategory(uint(id)); nil != err {
if err := service.Category.RemoveCategory(uint64(id)); nil != err {
result.Code = -1
result.Msg = err.Error()
}
Expand Down
6 changes: 3 additions & 3 deletions controller/console/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ func RemoveCommentAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

if err := service.Comment.RemoveComment(uint(id)); nil != err {
if err := service.Comment.RemoveComment(id); nil != err {
result.Code = -1
result.Msg = err.Error()
}
Expand All @@ -107,7 +107,7 @@ func RemoveCommentsAction(c *gin.Context) {

ids := arg["ids"].([]interface{})
for _, id := range ids {
if err := service.Comment.RemoveComment(uint(id.(float64))); nil != err {
if err := service.Comment.RemoveComment(uint64(id.(float64))); nil != err {
logger.Errorf("remove comment failed: " + err.Error())
}
}
Expand Down
10 changes: 5 additions & 5 deletions controller/console/consolestruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type ConsoleArticle struct {
ID uint `json:"id"`
ID uint64 `json:"id"`
Author *ConsoleAuthor `json:"author"`
CreatedAt string `json:"createdAt"`
Title string `json:"title"`
Expand All @@ -50,7 +50,7 @@ func (u *ConsoleAuthor) AvatarURLWithSize(size int) string {
}

type ConsoleCategory struct {
ID uint `json:"id"`
ID uint64 `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
Description string `json:"description"`
Expand All @@ -59,7 +59,7 @@ type ConsoleCategory struct {
}

type ConsoleComment struct {
ID uint `json:"id"`
ID uint64 `json:"id"`
Author *ConsoleAuthor `json:"author"`
ArticleAuthor *ConsoleAuthor `json:"articleAuthor"`
CreatedAt string `json:"createdAt"`
Expand All @@ -69,7 +69,7 @@ type ConsoleComment struct {
}

type ConsoleNavigation struct {
ID uint `json:"id"`
ID uint64 `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
IconURL string `json:"iconURL"`
Expand All @@ -83,7 +83,7 @@ type ConsoleTheme struct {
}

type ConsoleUser struct {
ID uint `json:"id"`
ID uint64 `json:"id"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Role int `json:"role"`
Expand Down
12 changes: 6 additions & 6 deletions controller/console/navigationctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func GetNavigationAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1

return
}

data := service.Navigation.ConsoleGetNavigation(uint(id))
data := service.Navigation.ConsoleGetNavigation(uint64(id))
if nil == data {
result.Code = -1

Expand All @@ -80,15 +80,15 @@ func RemoveNavigationAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

if err := service.Navigation.RemoveNavigation(uint(id)); nil != err {
if err := service.Navigation.RemoveNavigation(uint64(id)); nil != err {
result.Code = -1
result.Msg = err.Error()
}
Expand All @@ -99,15 +99,15 @@ func UpdateNavigationAction(c *gin.Context) {
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
id, err := strconv.Atoi(idArg)
id, err := strconv.ParseUint(idArg, 10, 64)
if nil != err {
result.Code = -1
result.Msg = err.Error()

return
}

navigation := &model.Navigation{Model: model.Model{ID: uint(id)}}
navigation := &model.Navigation{Model: model.Model{ID: uint64(id)}}
if err := c.BindJSON(navigation); nil != err {
result.Code = -1
result.Msg = "parses update navigation request failed"
Expand Down
2 changes: 1 addition & 1 deletion model/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type Archive struct {
Month string `gorm:"size:2" json:"month"`
ArticleCount int `json:"articleCount"`

BlogID uint `sql:"index" json:"blogID"`
BlogID uint64 `sql:"index" json:"blogID"`
}
4 changes: 2 additions & 2 deletions model/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type Article struct {
Model

AuthorID uint `json:"authorID"`
AuthorID uint64 `json:"authorID"`
Title string `gorm:"size:128" json:"title"`
Tags string `gorm:"size:128" json:"tags"`
Content string `gorm:"type:text" json:"content"`
Expand All @@ -38,7 +38,7 @@ type Article struct {
UserAgent string `gorm:"size:255" json:"userAgent"`
PushedAt time.Time `json:"pushedAt"`

BlogID uint `sql:"index" json:"blogID"`
BlogID uint64 `sql:"index" json:"blogID"`
}

// Article statuses.
Expand Down
2 changes: 1 addition & 1 deletion model/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ type Category struct {
Tags string `gorm:"size:128" json:"tags"`
Number int `json:"number"` // for sorting

BlogID uint `sql:"index" json:"blogID"`
BlogID uint64 `sql:"index" json:"blogID"`
}
Loading

0 comments on commit 5bbe5f7

Please sign in to comment.