mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 10:16:15 +00:00
refactor: harden sqlite runtime and packaged startup flow
- refine config loading with --config and current-directory .env - improve sqlite busy handling and runtime DB tuning - restore telegram payment notification and wallet input flow - add behavior-based config and callback recovery tests
This commit is contained in:
+10
-15
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
var httpCmd = &cobra.Command{
|
||||
Use: "http",
|
||||
Short: "http服务",
|
||||
Long: "http服务相关命令",
|
||||
Short: "http service",
|
||||
Long: "http service commands",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
},
|
||||
}
|
||||
@@ -34,8 +34,8 @@ func init() {
|
||||
|
||||
var startCmd = &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "启动",
|
||||
Long: "启动http服务",
|
||||
Short: "start",
|
||||
Long: "start http service",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
bootstrap.InitApp()
|
||||
printBanner()
|
||||
@@ -48,23 +48,22 @@ func HttpServerStart() {
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
e.HTTPErrorHandler = customHTTPErrorHandler
|
||||
// 中间件注册
|
||||
|
||||
MiddlewareRegister(e)
|
||||
// 路由注册
|
||||
route.RegisterRoute(e)
|
||||
// 静态目录注册
|
||||
e.Static(config.StaticPath, "static")
|
||||
e.Static(config.StaticPath, config.StaticFilePath)
|
||||
|
||||
httpListen := viper.GetString("http_listen")
|
||||
go func() {
|
||||
if err = e.Start(httpListen); err != http.ErrServerClosed {
|
||||
log.Sugar.Error(err)
|
||||
}
|
||||
}()
|
||||
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
|
||||
// Use a buffered channel to avoid missing signals as recommended for signal.Notify
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, os.Interrupt, os.Kill)
|
||||
<-quit
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err = e.Shutdown(ctx); err != nil {
|
||||
@@ -72,16 +71,13 @@ func HttpServerStart() {
|
||||
}
|
||||
}
|
||||
|
||||
// MiddlewareRegister 中间件注册
|
||||
func MiddlewareRegister(e *echo.Echo) {
|
||||
if config.AppDebug {
|
||||
e.Debug = true
|
||||
if config.HTTPAccessLog {
|
||||
e.Use(echoMiddleware.Logger())
|
||||
}
|
||||
e.Use(middleware.RequestUUID())
|
||||
}
|
||||
|
||||
// customHTTPErrorHandler 默认消息提示
|
||||
func customHTTPErrorHandler(err error, e echo.Context) {
|
||||
code := http.StatusInternalServerError
|
||||
msg := "server error"
|
||||
@@ -99,5 +95,4 @@ func customHTTPErrorHandler(err error, e echo.Context) {
|
||||
resp.Message = he.Msg
|
||||
}
|
||||
_ = e.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user