Skip to content

Commit

Permalink
♻️ 引入 Gulu 工具库
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 24, 2019
1 parent be30b56 commit 2b5d3e0
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 80 deletions.
4 changes: 2 additions & 2 deletions controller/accountctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package controller
import (
"net/http"

"github.com/b3log/pipe/util"
"github.com/b3log/gulu"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)

// logoutAction logout a user.
func logoutAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := sessions.Default(c)
Expand Down
5 changes: 3 additions & 2 deletions controller/b3logctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package controller

import (
"github.com/b3log/gulu"
"net/http"
"strconv"

Expand All @@ -28,7 +29,7 @@ import (

// addSymCommentAction adds a comment come from Sym. Sees https://hacpai.com/article/1457158841475 for more details.
func addSymCommentAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand Down Expand Up @@ -103,7 +104,7 @@ func addSymCommentAction(c *gin.Context) {

// addSymArticleAction adds an article come from Sym. Sees https://hacpai.com/article/1457158841475 for more details.
func addSymArticleAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand Down
5 changes: 3 additions & 2 deletions controller/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"bytes"
"github.com/b3log/gulu"
"html/template"
"net/http"
"strconv"
Expand All @@ -30,7 +31,7 @@ import (
)

func getRepliesAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

blogID := getBlogID(c)
Expand Down Expand Up @@ -69,7 +70,7 @@ func getRepliesAction(c *gin.Context) {
}

func addCommentAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

blogID := getBlogID(c)
Expand Down
5 changes: 3 additions & 2 deletions controller/console/accountctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package console

import (
"github.com/b3log/gulu"
"net/http"

"github.com/b3log/pipe/service"
Expand All @@ -26,7 +27,7 @@ import (

// UpdateAccountAction updates an account.
func UpdateAccountAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand Down Expand Up @@ -57,7 +58,7 @@ func UpdateAccountAction(c *gin.Context) {

// GetAccountAction gets an account.
func GetAccountAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down
22 changes: 11 additions & 11 deletions controller/console/articlectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var logger = gulu.Log.NewLogger(os.Stdout)

// PushArticle2RhyAction pushes an article to community.
func PushArticle2RhyAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -63,7 +63,7 @@ func PushArticle2RhyAction(c *gin.Context) {

// MarkdownAction handles markdown text to HTML.
func MarkdownAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand All @@ -84,7 +84,7 @@ var uploadToken, uploadURL = "", "https://hacpai.com/upload/client"

// UploadTokenAction gets a upload token.
func UploadTokenAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down Expand Up @@ -116,7 +116,7 @@ func UploadTokenAction(c *gin.Context) {
"userB3Key": session.UB3Key,
}

requestResult := util.NewResult()
requestResult := gulu.Ret.NewResult()
_, _, errs := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
Post(util.HacPaiURL+"/apis/upload/token").
SendStruct(requestJSON).Set("user-agent", model.UserAgent).Timeout(10 * time.Second).EndStruct(requestResult)
Expand Down Expand Up @@ -145,7 +145,7 @@ func UploadTokenAction(c *gin.Context) {

// AddArticleAction adds a new article.
func AddArticleAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand Down Expand Up @@ -196,7 +196,7 @@ func AddArticleAction(c *gin.Context) {

// GetArticleAction gets an article.
func GetArticleAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -222,7 +222,7 @@ func GetArticleAction(c *gin.Context) {

// GetArticlesAction gets articles.
func GetArticlesAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down Expand Up @@ -271,7 +271,7 @@ func GetArticlesAction(c *gin.Context) {

// RemoveArticleAction removes an article.
func RemoveArticleAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -294,7 +294,7 @@ func RemoveArticleAction(c *gin.Context) {

// RemoveArticlesAction removes articles.
func RemoveArticlesAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand All @@ -318,7 +318,7 @@ func RemoveArticlesAction(c *gin.Context) {

// UpdateArticleAction updates an article.
func UpdateArticleAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand Down Expand Up @@ -382,7 +382,7 @@ func UpdateArticleAction(c *gin.Context) {

// GetArticleThumbsAction gets article thumbnails.
func GetArticleThumbsAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

n, _ := strconv.Atoi(c.Query("n"))
Expand Down
3 changes: 2 additions & 1 deletion controller/console/authmidware.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package console
import (
"net/http"

"github.com/b3log/gulu"
"github.com/b3log/pipe/util"
"github.com/gin-gonic/gin"
)
Expand All @@ -27,7 +28,7 @@ import (
func LoginCheck(c *gin.Context) {
session := util.GetSession(c)
if 0 == session.UID {
result := util.NewResult()
result := gulu.Ret.NewResult()
result.Code = util.CodeAuthErr
result.Msg = "unauthenticated request"
c.AbortWithStatusJSON(http.StatusOK, result)
Expand Down
5 changes: 3 additions & 2 deletions controller/console/blogctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package console

import (
"crypto/tls"
"github.com/b3log/gulu"
"net/http"
"strconv"
"time"
Expand All @@ -31,7 +32,7 @@ import (

// BlogSwitchAction switches blog.
func BlogSwitchAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand Down Expand Up @@ -78,7 +79,7 @@ func BlogSwitchAction(c *gin.Context) {

// CheckVersionAction checks version.
func CheckVersionAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

rhyResult := map[string]interface{}{}
Expand Down
11 changes: 6 additions & 5 deletions controller/console/categoryctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package console

import (
"github.com/b3log/gulu"
"net/http"
"strconv"

Expand All @@ -28,7 +29,7 @@ import (

// UpdateCategoryAction updates a category.
func UpdateCategoryAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand Down Expand Up @@ -59,7 +60,7 @@ func UpdateCategoryAction(c *gin.Context) {

// GetCategoryAction gets a category.
func GetCategoryAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -83,7 +84,7 @@ func GetCategoryAction(c *gin.Context) {

// GetCategoriesAction gets categories.
func GetCategoriesAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand All @@ -110,7 +111,7 @@ func GetCategoriesAction(c *gin.Context) {

// AddCategoryAction adds a category.
func AddCategoryAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand All @@ -132,7 +133,7 @@ func AddCategoryAction(c *gin.Context) {

// RemoveCategoryAction removes a category.
func RemoveCategoryAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand Down
7 changes: 4 additions & 3 deletions controller/console/commentctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package console

import (
"github.com/b3log/gulu"
"html/template"
"net/http"
"strconv"
Expand All @@ -29,7 +30,7 @@ import (

// GetCommentsAction gets comments
func GetCommentsAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down Expand Up @@ -82,7 +83,7 @@ func GetCommentsAction(c *gin.Context) {

// RemoveCommentAction removes a comment.
func RemoveCommentAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -105,7 +106,7 @@ func RemoveCommentAction(c *gin.Context) {

// RemoveCommentsAction removes comments.
func RemoveCommentsAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
Expand Down
2 changes: 1 addition & 1 deletion controller/console/exportctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// ExportMarkdownAction exports articles as markdown zip file.
func ExportMarkdownAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down
2 changes: 1 addition & 1 deletion controller/console/importctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// ImportMarkdownAction imports markdown zip file as articles.
func ImportMarkdownAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down
11 changes: 6 additions & 5 deletions controller/console/navigationctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package console

import (
"github.com/b3log/gulu"
"net/http"
"strconv"

Expand All @@ -28,7 +29,7 @@ import (

// GetNavigationsAction gets navigations.
func GetNavigationsAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down Expand Up @@ -56,7 +57,7 @@ func GetNavigationsAction(c *gin.Context) {

// GetNavigationAction gets a navigation.
func GetNavigationAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -79,7 +80,7 @@ func GetNavigationAction(c *gin.Context) {

// RemoveNavigationAction remove a navigation.
func RemoveNavigationAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand All @@ -102,7 +103,7 @@ func RemoveNavigationAction(c *gin.Context) {

// UpdateNavigationAction updates a navigation.
func UpdateNavigationAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

idArg := c.Param("id")
Expand Down Expand Up @@ -133,7 +134,7 @@ func UpdateNavigationAction(c *gin.Context) {

// AddNavigationAction adds a navigation.
func AddNavigationAction(c *gin.Context) {
result := util.NewResult()
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

session := util.GetSession(c)
Expand Down
Loading

0 comments on commit 2b5d3e0

Please sign in to comment.