Skip to content

Commit

Permalink
🍎 detail
Browse files Browse the repository at this point in the history
  • Loading branch information
xzghua committed May 17, 2019
1 parent aace945 commit 7486a32
Show file tree
Hide file tree
Showing 90 changed files with 1,438 additions and 173 deletions.
9 changes: 8 additions & 1 deletion common/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
package common

import "strconv"
import (
"strconv"
"time"
)

func Offset(page string,limit string) (limitInt int,offset int) {
pageInt,err := strconv.Atoi(page)
Expand Down Expand Up @@ -94,4 +97,8 @@ func Rem(divisor int) bool {
} else {
return false
}
}

func MDate(times time.Time) string {
return times.Format("2006-01-02")
}
4 changes: 3 additions & 1 deletion common/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package common


var Permissions = []string{
"GET/console.post.index",
"GET/console.post.create",
Expand Down Expand Up @@ -34,6 +33,9 @@ var Permissions = []string{
"GET/console.link.edit",
"PUT/console.link.update",
"DELETE/console.link.destroy",
"DELETE/console.auth.logout",
"GET/console.home.index",
"DELETE/console.auth.cache",
}

func CheckPermissions(permission string,method string) bool {
Expand Down
32 changes: 32 additions & 0 deletions common/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package common

import (
"github.com/izghua/go-blog/entity"
"html/template"
"time"
)

Expand Down Expand Up @@ -121,3 +123,33 @@ type Paginate struct {
Next int `json:"next"`
}

type IndexPost struct {
Id int `json:"id,omitempty"`
Uid string `json:"uid,omitempty"`
UserId int `json:"userId,omitempty"`
Title string `json:"title,omitempty"`
Summary string `json:"summary,omitempty"`
Original string `json:"original,omitempty"`
Content template.HTML `json:"content,omitempty"`
Password string `json:"password,omitempty"`
DeletedAt time.Time `json:"deletedAt,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}

type IndexPostDetail struct {
Post IndexPost `json:"post,omitempty"`
Tags []ConsoleTag `json:"tags,omitempty"`
Category ConsoleCate `json:"category,omitempty"`
View ConsoleView `json:"view,omitempty"`
Author ConsoleUser `json:"author,omitempty"`
LastPost *entity.ZPosts `json:"lastPost,omitempty"`
NextPost *entity.ZPosts `json:"nextPost,omitempty"`
}

type IndexGithubParam struct {
GithubName string
GithubRepo string
GithubClientId string
GithubClientSecret string
}
10 changes: 9 additions & 1 deletion conf/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (

DataCacheTimeDuration = 720
ImgUploadUrl = "http://localhost:8081/console/post/imgUpload"
ImgUploadDst = "./static/images/uploads/"
ImgUploadDst = "./static/uploads/images/"
ImgUploadBoth = true // img will upload to qiniu and your server local

//qiniu
Expand Down Expand Up @@ -85,5 +85,13 @@ const (

LinkIndexKey = "index:all:link:list"
SystemIndexKey = "index:all:system:list"

PostDetailIndexKey = "index:post:detail"

// github gitment
GithubName = "xzghua"
GithubRepo = "ttest"
GithubClientId = "e298594e1aae93dbdaa7"
GithubClientSecret = "02fd3cccdd51d28ec861aa509fd73bb0a5c15ca1"
)

9 changes: 9 additions & 0 deletions conf/e.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,14 @@ var Msg = map[int]string{
407000011: "登录失败,请检查后再试",
407000012: "用户名不能为空,请检查后再试",
407000013: "用户名长度超出,请检查后再试",
407000014: "操作失败,请检查后再试",

// index
408000000: "常规信息查询失败,请检查后再试",
408000001: "文章列表获取失败,请检查后再试",
408000002: "文章详情获取失败,请检查后再试",
408000003: "文章标签获取失败,请检查后再试",
408000004: "文章标签获取失败,请检查后再试",
408000005: "文章分类获取失败,请检查后再试",
}

3 changes: 2 additions & 1 deletion middleware/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Permission(routerAsName string) gin.HandlerFunc {
fmt.Println(routerAsName,c.Request.Method)
res := common.CheckPermissions(routerAsName,c.Request.Method)
if !res {
zgh.ZLog().Error("method","middleware.Permission","info","router permission")
zgh.ZLog().Error("method","middleware.Permission","info","router permission","router name",routerAsName,"method",c.Request.Method)
apiG.Response(http.StatusOK,400001005,nil)
return
}
Expand Down Expand Up @@ -53,6 +53,7 @@ func Permission(routerAsName string) gin.HandlerFunc {
return
}
c.Set("userId",userIdInt)
c.Set("token",token)
//if routerAsName == "" {
// apiG.Response(http.StatusOK,0,nil)
// return
Expand Down
28 changes: 28 additions & 0 deletions router/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type ConsoleAuth interface {
AuthRegister(*gin.Context)
Login(*gin.Context)
AuthLogin(*gin.Context)
Logout(*gin.Context)
DelCache(*gin.Context)
}


Expand Down Expand Up @@ -183,3 +185,29 @@ func (c *Auth) AuthLogin(ctx *gin.Context) {
appG.Response(http.StatusOK,0,token)
return
}

func (c *Auth)Logout(ctx *gin.Context) {
appG := api.Gin{C: ctx}
token,exist := ctx.Get("token")
if !exist || token == ""{
zgh.ZLog().Error("message","auth.Logout","error","Can not get token")
appG.Response(http.StatusOK,400001004,nil)
return
}
_,err := jwt.UnsetToken(token.(string))
if err != nil {
zgh.ZLog().Error("message","auth.Logout","error",err.Error())
appG.Response(http.StatusOK,407000014,nil)
return
}
appG.Response(http.StatusOK,0,token)
return
}


func (c *Auth)DelCache(ctx *gin.Context) {
appG := api.Gin{C: ctx}
service.DelAllCache()
appG.Response(http.StatusOK,0,nil)
return
}
8 changes: 4 additions & 4 deletions router/console/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func (h *HomeStatistics)Index(c *gin.Context) {
Title: "标签总数",
Icon: "md-share",
Count: tagCnt,
Color: "#ed3f14",
Color: "#39ed14",
}
data = append(data,tcnt)
qcnt := Res{
Title: "未知问题",
Icon: "md-share",
Count: 999,
Title: "未知BUG",
Icon: "ios-bug",
Count: 998,
Color: "#ed3f14",
}
data = append(data,qcnt)
Expand Down
2 changes: 0 additions & 2 deletions router/console/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package console

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/izghua/go-blog/common"
"github.com/izghua/go-blog/conf"
Expand Down Expand Up @@ -66,7 +65,6 @@ func (t *Tag)Store(c *gin.Context) {
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")
Expand Down
47 changes: 47 additions & 0 deletions router/index/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Created by GoLand.
* User: zhu
* Email: ylsc633@gmail.com
* Date: 2019-05-17
* Time: 11:18
*/
package index

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/izghua/zgh"
"github.com/izghua/zgh/conf"
"net/http"
"strconv"
"time"
)

type ApiController struct {
C *gin.Context
}



func (a *ApiController) Response(httpCode, errCode int, data gin.H) {
if data == nil {
panic("常规信息应该设置")
}
msg := conf.GetMsg(errCode)
beginTime, _ := strconv.ParseInt(a.C.Writer.Header().Get("X-Begin-Time"), 10, 64)

duration := time.Now().Sub(time.Unix(0, beginTime))
milliseconds := float64(duration) / float64(time.Millisecond)
rounded := float64(int(milliseconds*100+.5)) / 100
roundedStr := fmt.Sprintf("%.3fms", rounded)
a.C.Writer.Header().Set("X-Response-time", roundedStr)
zgh.ZLog().Info("message", "Index Response", "code", errCode, "errMsg", msg, "took", roundedStr)
if errCode != 0 {
a.C.HTML(http.StatusOK,"5xx.tmpl",data)
} else {
a.C.HTML(http.StatusOK,"master.tmpl",data)
}

a.C.Abort()
return
}
1 change: 1 addition & 0 deletions router/index/i.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ type Home interface {
Index(*gin.Context)
IndexTag(*gin.Context)
IndexCate(*gin.Context)
Detail(*gin.Context)
Archives(*gin.Context)
}
Loading

0 comments on commit 7486a32

Please sign in to comment.