mirror of
https://github.com/go-nunu/nunu-layout-advanced.git
synced 2025-09-26 20:41:33 +08:00
fix: check ParseToken err
This commit is contained in:
@@ -23,7 +23,9 @@ var serverSet = wire.NewSet(
|
||||
)
|
||||
|
||||
// build App
|
||||
func newApp(migrate *server.Migrate) *app.App {
|
||||
func newApp(
|
||||
migrate *server.Migrate,
|
||||
) *app.App {
|
||||
return app.NewApp(
|
||||
app.WithServer(migrate),
|
||||
app.WithName("demo-migrate"),
|
||||
|
@@ -32,6 +32,8 @@ var repositorySet = wire.NewSet(repository.NewDB, repository.NewRepository, repo
|
||||
var serverSet = wire.NewSet(server.NewMigrate)
|
||||
|
||||
// build App
|
||||
func newApp(migrate *server.Migrate) *app.App {
|
||||
func newApp(
|
||||
migrate *server.Migrate,
|
||||
) *app.App {
|
||||
return app.NewApp(app.WithServer(migrate), app.WithName("demo-migrate"))
|
||||
}
|
||||
|
@@ -41,7 +41,11 @@ var serverSet = wire.NewSet(
|
||||
)
|
||||
|
||||
// build App
|
||||
func newApp(httpServer *http.Server, job *server.Job) *app.App {
|
||||
func newApp(
|
||||
httpServer *http.Server,
|
||||
job *server.Job,
|
||||
// task *server.Task,
|
||||
) *app.App {
|
||||
return app.NewApp(
|
||||
app.WithServer(httpServer, job),
|
||||
app.WithName("demo-server"),
|
||||
@@ -49,7 +53,6 @@ func newApp(httpServer *http.Server, job *server.Job) *app.App {
|
||||
}
|
||||
|
||||
func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
|
||||
|
||||
panic(wire.Build(
|
||||
repositorySet,
|
||||
serviceSet,
|
||||
|
@@ -51,6 +51,10 @@ var handlerSet = wire.NewSet(handler.NewHandler, handler.NewUserHandler)
|
||||
var serverSet = wire.NewSet(server.NewHTTPServer, server.NewJob)
|
||||
|
||||
// build App
|
||||
func newApp(httpServer *http.Server, job *server.Job) *app.App {
|
||||
func newApp(
|
||||
httpServer *http.Server,
|
||||
job *server.Job,
|
||||
|
||||
) *app.App {
|
||||
return app.NewApp(app.WithServer(httpServer, job), app.WithName("demo-server"))
|
||||
}
|
||||
|
@@ -16,7 +16,9 @@ var serverSet = wire.NewSet(
|
||||
)
|
||||
|
||||
// build App
|
||||
func newApp(task *server.Task) *app.App {
|
||||
func newApp(
|
||||
task *server.Task,
|
||||
) *app.App {
|
||||
return app.NewApp(
|
||||
app.WithServer(task),
|
||||
app.WithName("demo-task"),
|
||||
|
@@ -28,6 +28,8 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*app.App, func(), err
|
||||
var serverSet = wire.NewSet(server.NewTask)
|
||||
|
||||
// build App
|
||||
func newApp(task *server.Task) *app.App {
|
||||
func newApp(
|
||||
task *server.Task,
|
||||
) *app.App {
|
||||
return app.NewApp(app.WithServer(task), app.WithName("demo-task"))
|
||||
}
|
||||
|
52
docs/docs.go
52
docs/docs.go
@@ -116,6 +116,42 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"用户模块"
|
||||
],
|
||||
"summary": "修改用户信息",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "params",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.GetProfileResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -213,6 +249,22 @@ const docTemplate = `{
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"email"
|
||||
],
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"example": "1234@gmail.com"
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string",
|
||||
"example": "alan"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
|
@@ -109,6 +109,42 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"用户模块"
|
||||
],
|
||||
"summary": "修改用户信息",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "params",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.GetProfileResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -206,6 +242,22 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"email"
|
||||
],
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"example": "1234@gmail.com"
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string",
|
||||
"example": "alan"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
|
@@ -62,6 +62,17 @@ definitions:
|
||||
message:
|
||||
type: string
|
||||
type: object
|
||||
github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest:
|
||||
properties:
|
||||
email:
|
||||
example: 1234@gmail.com
|
||||
type: string
|
||||
nickname:
|
||||
example: alan
|
||||
type: string
|
||||
required:
|
||||
- email
|
||||
type: object
|
||||
host: localhost:8000
|
||||
info:
|
||||
contact:
|
||||
@@ -135,6 +146,28 @@ paths:
|
||||
summary: 获取用户信息
|
||||
tags:
|
||||
- 用户模块
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: params
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.UpdateProfileRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_go-nunu_nunu-layout-advanced_api_v1.GetProfileResponse'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: 修改用户信息
|
||||
tags:
|
||||
- 用户模块
|
||||
securityDefinitions:
|
||||
Bearer:
|
||||
in: header
|
||||
|
@@ -10,7 +10,9 @@ type Handler struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func NewHandler(logger *log.Logger) *Handler {
|
||||
func NewHandler(
|
||||
logger *log.Logger,
|
||||
) *Handler {
|
||||
return &Handler{
|
||||
logger: logger,
|
||||
}
|
||||
|
@@ -99,6 +99,17 @@ func (h *UserHandler) GetProfile(ctx *gin.Context) {
|
||||
v1.HandleSuccess(ctx, user)
|
||||
}
|
||||
|
||||
// UpdateProfile godoc
|
||||
// @Summary 修改用户信息
|
||||
// @Schemes
|
||||
// @Description
|
||||
// @Tags 用户模块
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Param request body v1.UpdateProfileRequest true "params"
|
||||
// @Success 200 {object} v1.GetProfileResponse
|
||||
// @Router /user [put]
|
||||
func (h *UserHandler) UpdateProfile(ctx *gin.Context) {
|
||||
userId := GetUserIdFromCtx(ctx)
|
||||
|
||||
|
@@ -34,6 +34,7 @@ func NewHTTPServer(
|
||||
swaggerfiles.Handler,
|
||||
//ginSwagger.URL(fmt.Sprintf("http://localhost:%d/swagger/doc.json", conf.GetInt("app.http.port"))),
|
||||
ginSwagger.DefaultModelsExpandDepth(-1),
|
||||
ginSwagger.PersistAuthorization(true),
|
||||
))
|
||||
|
||||
s.Use(
|
||||
|
@@ -14,7 +14,12 @@ type Service struct {
|
||||
tm repository.Transaction
|
||||
}
|
||||
|
||||
func NewService(tm repository.Transaction, logger *log.Logger, sid *sid.Sid, jwt *jwt.JWT) *Service {
|
||||
func NewService(
|
||||
tm repository.Transaction,
|
||||
logger *log.Logger,
|
||||
sid *sid.Sid,
|
||||
jwt *jwt.JWT,
|
||||
) *Service {
|
||||
return &Service{
|
||||
logger: logger,
|
||||
sid: sid,
|
||||
|
@@ -53,6 +53,9 @@ func (j *JWT) ParseToken(tokenString string) (*MyCustomClaims, error) {
|
||||
token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return j.key, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if claims, ok := token.Claims.(*MyCustomClaims); ok && token.Valid {
|
||||
return claims, nil
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user