add: app info
This commit is contained in:
parent
4977a30280
commit
ed7cfb418c
|
@ -1,6 +1,7 @@
|
||||||
app:
|
app:
|
||||||
|
name: 'potato'
|
||||||
|
version: '1.0.0'
|
||||||
jwt_secret: 'viletyy'
|
jwt_secret: 'viletyy'
|
||||||
jwt_issuer: 'potato'
|
|
||||||
jwt_expire: '7200'
|
jwt_expire: '7200'
|
||||||
run_mode: 'debug'
|
run_mode: 'debug'
|
||||||
page_size: 10
|
page_size: 10
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* @Date: 2021-03-22 09:46:19
|
* @Date: 2021-03-22 09:46:19
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-06-11 16:40:34
|
* @LastEditTime: 2021-06-13 22:00:01
|
||||||
* @FilePath: /potato/config/app.go
|
* @FilePath: /potato/config/app.go
|
||||||
*/
|
*/
|
||||||
package config
|
package config
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
|
Name string `mapstructure:"name" json:"name" yaml:"name"`
|
||||||
|
Version string `mapstructure:"version" json:"version" yaml:"version"`
|
||||||
PageSize int64 `mapstructure:"page_size" json:"page_size" yaml:"page_size"`
|
PageSize int64 `mapstructure:"page_size" json:"page_size" yaml:"page_size"`
|
||||||
JwtSecret string `mapstructure:"jwt_secret" json:"jwt_secret" yaml:"jwt_secret"`
|
JwtSecret string `mapstructure:"jwt_secret" json:"jwt_secret" yaml:"jwt_secret"`
|
||||||
JwtIssuser string `mapstructure:"jwt_issuser" json:"jwt_issuser" yaml:"jwt_issuser"`
|
|
||||||
JwtExpire int64 `mapstructure:"jwt_expire" json:"jwt_expire" yaml:"jwt_expire"`
|
JwtExpire int64 `mapstructure:"jwt_expire" json:"jwt_expire" yaml:"jwt_expire"`
|
||||||
RunMode string `mapstructure:"run_mode" json:"run_mode" yaml:"run_mode"`
|
RunMode string `mapstructure:"run_mode" json:"run_mode" yaml:"run_mode"`
|
||||||
UploadSavePath string `mapstructure:"upload_save_path" json:"upload_save_path" yaml:"upload_save_path"`
|
UploadSavePath string `mapstructure:"upload_save_path" json:"upload_save_path" yaml:"upload_save_path"`
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* @Date: 2021-06-13 22:01:30
|
||||||
|
* @LastEditors: viletyy
|
||||||
|
* @LastEditTime: 2021-06-13 22:02:41
|
||||||
|
* @FilePath: /potato/internal/middleware/app_info.go
|
||||||
|
*/
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/viletyy/potato/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AppInfo() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Set("app_name", global.GO_CONFIG.App.Name)
|
||||||
|
c.Set("app_version", global.GO_CONFIG.App.Version)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Date: 2021-03-21 19:54:57
|
* @Date: 2021-03-21 19:54:57
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-06-12 22:24:53
|
* @LastEditTime: 2021-06-13 22:03:27
|
||||||
* @FilePath: /potato/internal/routers/router.go
|
* @FilePath: /potato/internal/routers/router.go
|
||||||
*/
|
*/
|
||||||
package routers
|
package routers
|
||||||
|
@ -35,6 +35,7 @@ func InitRouter() *gin.Engine {
|
||||||
|
|
||||||
Engine.Use(middleware.CORS())
|
Engine.Use(middleware.CORS())
|
||||||
Engine.Use(middleware.AccessLog())
|
Engine.Use(middleware.AccessLog())
|
||||||
|
Engine.Use(middleware.AppInfo())
|
||||||
Engine.StaticFS("/static", http.Dir(global.GO_CONFIG.App.UploadSavePath))
|
Engine.StaticFS("/static", http.Dir(global.GO_CONFIG.App.UploadSavePath))
|
||||||
|
|
||||||
Engine.POST("/api/v1/auth", v1.GetAuth)
|
Engine.POST("/api/v1/auth", v1.GetAuth)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Date: 2021-06-10 18:25:19
|
* @Date: 2021-06-10 18:25:19
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-06-10 22:23:51
|
* @LastEditTime: 2021-06-13 22:00:15
|
||||||
* @FilePath: /potato/pkg/app/jwt.go
|
* @FilePath: /potato/pkg/app/jwt.go
|
||||||
*/
|
*/
|
||||||
package app
|
package app
|
||||||
|
@ -33,7 +33,7 @@ func GenerateToken(appKey, appSecret string) (string, error) {
|
||||||
AppSecret: crypt.Md5Encode(appSecret),
|
AppSecret: crypt.Md5Encode(appSecret),
|
||||||
StandardClaims: jwt.StandardClaims{
|
StandardClaims: jwt.StandardClaims{
|
||||||
ExpiresAt: expireTime.Unix(),
|
ExpiresAt: expireTime.Unix(),
|
||||||
Issuer: global.GO_CONFIG.App.JwtIssuser,
|
Issuer: global.GO_CONFIG.App.Name,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue