yshop-gin-2 发表于 2023-07-11 | 更新于 2024-09-02 | 分类于 Gin 本文字数: 17k | 阅读时长 ≈ 16 分钟 思考并回答以下问题: 根目录1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253server: run-mode: 'release' http-port: 8000 read-timeout: 60 write-timeout: 60app: page-size: 10 jwt-secret: go-mall prefix-url: 'http://127.0.0.1:8000' runtime-root-path: 'runtime/' image-save-path: 'upload/images/' # MB image-max-size: 5242880 image-allow-exts: ['.jpg','.jpeg','.png'] export-save-path: 'export/' qrcode-save-path: 'qrcode/' font-save-path: 'fonts/' log-save-path: 'logs/' Log-save-name: 'log' Log-file-ext: 'log' time-format: 20060102database: type: 'mysql' user: 'root' password: 'root' host: '127.0.0.1:3306' name: 'yshop_go' table_prefix:redis: host: '127.0.0.1:6379' password: max_idle: 30 max_active: 30 idle_timeout: 200zap: log-filepath: 'runtime/logs' log-info-filename: 'info' log-warn-filename: 'warn' log-fiile-ext: 'log'wechat: app_id: app_secret: token: yshop-gin encoding_aes_key:express: eBusinessId: 1607734 appKey: 81f43a2e-f504-45c4-9b54-2637d59f8190 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960package mainimport ( "fmt" "github.com/spf13/cobra" "os" "yixiang.co/go-mall/app/listen" "yixiang.co/go-mall/app/models" "yixiang.co/go-mall/cmd" "yixiang.co/go-mall/pkg/config" "yixiang.co/go-mall/pkg/console" "yixiang.co/go-mall/pkg/global" "yixiang.co/go-mall/pkg/jwt" "yixiang.co/go-mall/pkg/logging" "yixiang.co/go-mall/pkg/redis" "yixiang.co/go-mall/pkg/wechat")func init() { global.YSHOP_VP = config.Viper() global.YSHOP_LOG = logging.SetupLogger() models.Setup() logging.Setup() redis.Setup() jwt.Setup() listen.Setup() wechat.InitWechat()}// @title gin-shop API// @version 1.0// @description gin-shop商城后台管理系统// @termsOfService https://gitee.com/guchengwuyue/gin-shop// @license.name apache2func main() { var rootCmd = &cobra.Command{ Use: "yshop=gin", Short: "gin商城系统r", Long: "will run serve command", PersistentPreRun: func(cmd *cobra.Command, args []string) { }, } rootCmd.AddCommand(cmd.CmdServe) // 配置默认运行 Web 服务 cmd.RegisterDefaultCmd(rootCmd, cmd.CmdServe) // 注册全局参数,--env cmd.RegisterGlobalFlags(rootCmd) // 执行主命令 if err := rootCmd.Execute(); err != nil { console.Exit(fmt.Sprintf("Failed to run app with %v: %s", os.Args, err.Error())) }} routers12345678910111213141516171819202122232425262728293031323334package routersimport ( "github.com/gin-gonic/gin" "github.com/swaggo/gin-swagger" "github.com/swaggo/gin-swagger/swaggerFiles" "net/http" _ "yixiang.co/go-mall/docs" "yixiang.co/go-mall/middleware" "yixiang.co/go-mall/pkg/upload" "yixiang.co/go-mall/routers/admin")func InitRouter() *gin.Engine { r := gin.New() r.Use(gin.Logger()) r.Use(gin.Recovery()) r.Use(middleware.Cors()) r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath())) r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) //注册后台路由 admin.RegisterSystemRouters(r) admin.RegisterShopRouters(r) admin.RegisterToolsRouters(r) admin.RegisterWeixinRouters(r) //注册api 路由 //api.RegisterApiRouters(r) return r}