forked from izghua/go-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
223 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,7 @@ const ( | |
|
||
|
||
CateListKey = "all:cate:sort" | ||
TagListKey = "all:tag" | ||
|
||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Created by GoLand. | ||
* User: zhu | ||
* Email: ylsc633@gmail.com | ||
* Date: 2019-04-23 | ||
* Time: 19:25 | ||
*/ | ||
package console | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"github.com/izghua/go-blog/common" | ||
"github.com/izghua/go-blog/service" | ||
"github.com/izghua/zgh" | ||
"github.com/izghua/zgh/gin/api" | ||
"net/http" | ||
) | ||
|
||
type Tag struct { | ||
} | ||
|
||
func NewTag() Console { | ||
return &Tag{} | ||
} | ||
|
||
func (t *Tag)Index(c *gin.Context) { | ||
appG := api.Gin{C: c} | ||
tags,err := service.AllTags() | ||
if err != nil { | ||
zgh.ZLog().Error("message","console.Tag.Index","err",err.Error()) | ||
appG.Response(http.StatusOK,402000001,nil) | ||
return | ||
} | ||
appG.Response(http.StatusOK,0,tags) | ||
return | ||
} | ||
|
||
func (t *Tag)Create(c *gin.Context) { | ||
|
||
} | ||
|
||
func (t *Tag)Store(c *gin.Context) { | ||
appG := api.Gin{C: c} | ||
requestJson,exists := c.Get("json") | ||
if !exists { | ||
zgh.ZLog().Error("message","Tag.Store","error","get request_params from context fail") | ||
appG.Response(http.StatusOK,400001003,nil) | ||
return | ||
} | ||
var ts common.TagStore | ||
fmt.Println(requestJson,"000000") | ||
ts,ok := requestJson.(common.TagStore) | ||
if !ok { | ||
zgh.ZLog().Error("message","Tag.Store","error","request_params turn to error") | ||
appG.Response(http.StatusOK,400001001,nil) | ||
return | ||
} | ||
err := service.TagStore(ts) | ||
if err != nil { | ||
zgh.ZLog().Error("message","console.Cate.Store","err",err.Error()) | ||
appG.Response(http.StatusOK,403000006,nil) | ||
return | ||
} | ||
appG.Response(http.StatusOK,0,nil) | ||
return | ||
} | ||
|
||
func (t *Tag)Edit(c *gin.Context) { | ||
|
||
} | ||
|
||
func (t *Tag)Update(c *gin.Context) { | ||
|
||
} | ||
|
||
func (t *Tag)Destroy(c *gin.Context){ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Created by GoLand. | ||
* User: zhu | ||
* Email: ylsc633@gmail.com | ||
* Date: 2019-04-23 | ||
* Time: 17:46 | ||
*/ | ||
package validate | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/izghua/go-blog/common" | ||
"github.com/izghua/zgh/gin/api" | ||
"net/http" | ||
) | ||
|
||
type TagStoreV struct { | ||
} | ||
|
||
func (tv *TagStoreV) MyValidate() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
appG := api.Gin{C: c} | ||
var json common.TagStore | ||
//接收各种参数 | ||
if err := c.ShouldBindJSON(&json); err != nil { | ||
appG.Response(http.StatusOK, 400001000, nil) | ||
return | ||
} | ||
|
||
reqValidate := &TagStore{ | ||
Name:json.Name, | ||
DisplayName:json.DisplayName, | ||
SeoDesc:json.SeoDesc, | ||
} | ||
if b := appG.Validate(reqValidate); !b { | ||
return | ||
} | ||
c.Set("json",json) | ||
c.Next() | ||
} | ||
} | ||
|
||
type TagStore struct { | ||
Name string `valid:"Required;MaxSize(100)"` | ||
DisplayName string `valid:"Required;MaxSize(100)"` | ||
SeoDesc string `valid:"Required;MaxSize(250)"` | ||
} | ||
|
||
|
||
func (c *TagStore) Message() map[string]int { | ||
return map[string]int{ | ||
"Name.Required":403000000, | ||
"Name.MaxSize":403000001, | ||
"DisplayName.Required":403000002, | ||
"DisplayName.MaxSize":403000003, | ||
"SeoDesc.Required":403000004, | ||
"SeoDesc.MaxSize":403000005, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters