add models and jwt

This commit is contained in:
张超
2024-01-10 16:05:15 +08:00
parent 45bc7c5140
commit 2455f0d897
19 changed files with 990 additions and 4 deletions

30
serializers/pagination.go Normal file
View File

@@ -0,0 +1,30 @@
/*
@Time : 2020/7/16 23:44
@Author : xuyiqing
@File : common.py
*/
package serializers
import (
"github.com/gin-gonic/gin"
"strconv"
)
type Pager struct {
Page int `json:"page" form:"page"`
PageSize int `json:"pageSize" form:"pageSize"`
OffSet int `json:"-"`
Total int `json:"total"`
MaxPage int `json:"maxPage"`
}
func (p *Pager) InitPager(ctx *gin.Context) {
p.Page, _ = strconv.Atoi(ctx.DefaultQuery("page", "1"))
p.PageSize, _ = strconv.Atoi(ctx.DefaultQuery("pageSize", "10"))
p.OffSet = (p.Page - 1) * p.PageSize
}
func (p *Pager) GetPager() {
p.MaxPage = int(p.Total / p.PageSize) + 1
}

27
serializers/users.go Normal file
View File

@@ -0,0 +1,27 @@
/*
@Time : 2020/6/28 22:16
@Author : xuyiqing
@File : users.py
*/
package serializers
import "go_blog/models"
type Login struct {
Username string `form:"usernmae"; json:"username"`
Password string `form:"password"; json:"password"`
}
func (l *Login) GetUser() *models.Account {
return &models.Account{
Username: l.Username,
Password: l.Password,
}
}
type Account struct {
Username string `form:"username" json:"username"`
OldPwd string `form:"oldPwd" json:"oldPwd"`
NewPwd string `form:"newPwd"json:"newPwd"`
}