add: app info

This commit is contained in:
viletyy 2021-06-13 22:03:43 +08:00
parent 4977a30280
commit ed7cfb418c
5 changed files with 29 additions and 6 deletions

View File

@ -1,6 +1,7 @@
app:
name: 'potato'
version: '1.0.0'
jwt_secret: 'viletyy'
jwt_issuer: 'potato'
jwt_expire: '7200'
run_mode: 'debug'
page_size: 10

View File

@ -1,15 +1,16 @@
/*
* @Date: 2021-03-22 09:46:19
* @LastEditors: viletyy
* @LastEditTime: 2021-06-11 16:40:34
* @LastEditTime: 2021-06-13 22:00:01
* @FilePath: /potato/config/app.go
*/
package config
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"`
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"`
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"`

View File

@ -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()
}
}

View File

@ -1,7 +1,7 @@
/*
* @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy
* @LastEditTime: 2021-06-12 22:24:53
* @LastEditTime: 2021-06-13 22:03:27
* @FilePath: /potato/internal/routers/router.go
*/
package routers
@ -35,6 +35,7 @@ func InitRouter() *gin.Engine {
Engine.Use(middleware.CORS())
Engine.Use(middleware.AccessLog())
Engine.Use(middleware.AppInfo())
Engine.StaticFS("/static", http.Dir(global.GO_CONFIG.App.UploadSavePath))
Engine.POST("/api/v1/auth", v1.GetAuth)

View File

@ -1,7 +1,7 @@
/*
* @Date: 2021-06-10 18:25:19
* @LastEditors: viletyy
* @LastEditTime: 2021-06-10 22:23:51
* @LastEditTime: 2021-06-13 22:00:15
* @FilePath: /potato/pkg/app/jwt.go
*/
package app
@ -33,7 +33,7 @@ func GenerateToken(appKey, appSecret string) (string, error) {
AppSecret: crypt.Md5Encode(appSecret),
StandardClaims: jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: global.GO_CONFIG.App.JwtIssuser,
Issuer: global.GO_CONFIG.App.Name,
},
}