Skip to content

Commit

Permalink
fix(jwt): 1. debug 模式跳过鉴权 2. 修复tag标签路由错误的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
minibear2333 committed Jun 28, 2021
1 parent 0b36b41 commit c39befa
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# (2021-06-27)

### Features

* **jwt:** jwt api鉴权 ([f381a20](https://github.com/golang-minibear2333/gin-blog/commit/f381a209081a0b9b865589d88334609fceec6b7d)), closes [#12](https://github.com/golang-minibear2333/gin-blog/issues/12)
* **jwt:** jWT 权限校验模块 ([#13](https://github.com/golang-minibear2333/gin-blog/issues/13)) ([83236bc](https://github.com/golang-minibear2333/gin-blog/commit/83236bc06a13d3968f36b2c305f4f5f759f4b27b)), closes [#10](https://github.com/golang-minibear2333/gin-blog/issues/10)


# (2021-06-20)


Expand Down
6 changes: 5 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2021-06-27 18:25:38.010049 +0800 CST m=+0.067971498
// 2021-06-28 12:46:40.179811 +0800 CST m=+0.053454670

package docs

Expand Down Expand Up @@ -39,6 +39,7 @@ var doc = `{
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -111,6 +112,7 @@ var doc = `{
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -163,6 +165,7 @@ var doc = `{
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -217,6 +220,7 @@ var doc = `{
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down
4 changes: 4 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -93,6 +94,7 @@
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -145,6 +147,7 @@
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down Expand Up @@ -199,6 +202,7 @@
"parameters": [
{
"type": "string",
"default": "debug",
"description": "用户token",
"name": "token",
"in": "header",
Expand Down
12 changes: 8 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ paths:
/api/v1/tags:
get:
parameters:
- description: 用户token
- default: debug
description: 用户token
in: header
name: token
required: true
Expand Down Expand Up @@ -146,7 +147,8 @@ paths:
consumes:
- application/json
parameters:
- description: 用户token
- default: debug
description: 用户token
in: header
name: token
required: true
Expand Down Expand Up @@ -178,7 +180,8 @@ paths:
/api/v1/tags/{id}:
delete:
parameters:
- description: 用户token
- default: debug
description: 用户token
in: header
name: token
required: true
Expand Down Expand Up @@ -210,7 +213,8 @@ paths:
consumes:
- application/json
parameters:
- description: 用户token
- default: debug
description: 用户token
in: header
name: token
required: true
Expand Down
5 changes: 5 additions & 0 deletions internal/middleware/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package middleware
import (
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/golang-minibear2333/gin-blog/global"
"github.com/golang-minibear2333/gin-blog/pkg/app"
"github.com/golang-minibear2333/gin-blog/pkg/errcode"
)

func JWT() gin.HandlerFunc {
return func(c *gin.Context) {
if global.ServerSetting.RunMode == "debug"{
c.Next()
return
}
var (
token string
ecode = errcode.Success
Expand Down
8 changes: 4 additions & 4 deletions internal/routers/api/v1/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (t Tag) Get(c *gin.Context) {}
// @tags tag
// @Summary 获取多个标签
// @Produce json
// @Param token header string true "用户token"
// @Param token header string true "用户token" default(debug)
// @Param name query string false "标签名称" maxlength(100)
// @Param state query int false "状态,是否启用(0 为禁用、1 为启用)" Enums(0, 1) default(1)
// @Param page query int false "页码" default(1)
Expand Down Expand Up @@ -69,7 +69,7 @@ func (t Tag) List(c *gin.Context) {
// @Summary 新增标签
// @Produce json
// @accept json
// @Param token header string true "用户token"
// @Param token header string true "用户token" default(debug)
// @Param data body service.CreateTagRequest true "请求体"
// @Success 200 {object} model.Tag "成功"
// @Failure 400 {object} errcode.Error "请求错误"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (t Tag) Create(c *gin.Context) {
// @Summary 更新标签
// @Produce json
// @accept json
// @Param token header string true "用户token"
// @Param token header string true "用户token" default(debug)
// @Param id path int true "标签 ID"
// @Param data body service.UpdateTagRequest true "请求体"
// @Success 200 {object} model.Tag "成功"
Expand Down Expand Up @@ -135,7 +135,7 @@ func (t Tag) Update(c *gin.Context) {
// @Summary 删除标签
// @tags tag
// @Produce json
// @Param token header string true "用户token"
// @Param token header string true "用户token" default(debug)
// @Param id path int true "标签 ID"
// @Success 200 {string} string "成功"
// @Failure 400 {object} errcode.Error "请求错误"
Expand Down
8 changes: 4 additions & 4 deletions internal/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func NewRouter() *gin.Engine {
tags := v1.Group("/tags")
{
tags.POST("", tag.Create)
v1.DELETE(":id", tag.Delete)
v1.PUT(":id", tag.Update)
v1.PATCH(":id/state", tag.Update)
v1.GET("", tag.List)
tags.DELETE(":id", tag.Delete)
tags.PUT(":id", tag.Update)
tags.PATCH(":id/state", tag.Update)
tags.GET("", tag.List)
}
articles := v1.Group("/articles")
{
Expand Down
4 changes: 3 additions & 1 deletion scripts/build_swagger.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pushd ../ && swag init
# generate swagger doc
pushd ../ && swag init

0 comments on commit c39befa

Please sign in to comment.