Skip to content

Commit

Permalink
💡 b3log#108
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 26, 2018
1 parent 46e4ce8 commit b22220a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions cache/commentcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/bluele/gcache"
)

// Comment service.
var Comment = &commentCache{
idHolder: gcache.New(1024 * 10 * 10).LRU().Build(),
}
Expand Down
1 change: 1 addition & 0 deletions controller/console/devctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"math/rand"
)

// GenArticlesAction generates articles for testing.
func GenArticlesAction(c *gin.Context) {
session := util.GetSession(c)

Expand Down
1 change: 1 addition & 0 deletions controller/statusctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/gin-gonic/gin"
)

// Status represents platform status and blog info.
type Status struct {
*service.PlatformStatus

Expand Down
2 changes: 1 addition & 1 deletion log/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (l *Logger) Warn(v ...interface{}) {
l.logger.Output(2, fmt.Sprint(v...))
}

// Warn prints warning level message with format.
// Warnf prints warning level message with format.
func (l *Logger) Warnf(format string, v ...interface{}) {
if Warn < l.level {
return
Expand Down
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package model

import "time"

// Model represents meta data of entity.
type Model struct {
ID uint64 `gorm:"primary_key" json:"id"`
CreatedAt time.Time `json:"createdAt"`
Expand Down
1 change: 1 addition & 0 deletions service/settingsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/b3log/pipe/model"
)

// Setting service.
var Setting = &settingService{
mutex: &sync.Mutex{},
}
Expand Down
4 changes: 3 additions & 1 deletion theme/themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (
// Logger
var logger = log.NewLogger(os.Stdout)

// Default theme name.
const DefaultTheme = "Gina"

var Themes = []string{}
// All theme names.
var Themes []string

// Load loads themes.
func Load() {
Expand Down
1 change: 1 addition & 0 deletions util/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"
)

// ImageSize returns image URL of Qiniu image processing style with the specified width and height.
func ImageSize(imageURL string, width, height int) string {
return imageURL + "?imageView2/1/w/" + strconv.Itoa(width) + "/h/" + strconv.Itoa(height) + "/interlace/1/q/100"
}
Expand Down
3 changes: 3 additions & 0 deletions util/paginations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin"
)

// Pagination represents pagination info.
type Pagination struct {
CurrentPageNum int `json:"currentPageNum"`
PageSize int `json:"pageSize"`
Expand All @@ -37,6 +38,7 @@ type Pagination struct {
PageURL string `json:"pageURL"`
}

// GetPage returns paging parameter.
func GetPage(c *gin.Context) int {
ret, _ := strconv.Atoi(c.Query("p"))
if 1 > ret {
Expand All @@ -46,6 +48,7 @@ func GetPage(c *gin.Context) int {
return ret
}

// NewPagination creates a new pagination with the specified current page num, page size, window size and record count.
func NewPagination(currentPageNum, pageSize, windowSize, recordCount int) *Pagination {
pageCount := int(math.Ceil(float64(recordCount) / float64(pageSize)))

Expand Down
4 changes: 4 additions & 0 deletions util/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin"
)

// SessionData represents the session.
type SessionData struct {
UID uint64 // user ID
UName string // username
Expand All @@ -33,10 +34,12 @@ type SessionData struct {
BURL string // blog url
}

// AvatarURLWithSize returns avatar URL with the specified size.
func (sd *SessionData) AvatarURLWithSize(size int) string {
return ImageSize(sd.UAvatar, size, size)
}

// Save saves the current session of the specified context.
func (sd *SessionData) Save(c *gin.Context) error {
session := sessions.Default(c)
sessionDataBytes, err := json.Marshal(sd)
Expand All @@ -48,6 +51,7 @@ func (sd *SessionData) Save(c *gin.Context) error {
return session.Save()
}

// GetSession returns session of the specified context.
func GetSession(c *gin.Context) *SessionData {
ret := &SessionData{}

Expand Down

0 comments on commit b22220a

Please sign in to comment.