Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
[perf] 适配框架变更
Browse files Browse the repository at this point in the history
  • Loading branch information
kyour-cn committed Mar 15, 2023
1 parent 374fd99 commit ebcbde9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
9 changes: 7 additions & 2 deletions ghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ghttp
import (
"context"
"github.com/go-gourd/gourd/config"
"github.com/go-gourd/gourd/event"
"github.com/go-gourd/gourd/logger"
"go.uber.org/zap"
"net/http"
"strconv"
)
Expand All @@ -23,7 +23,7 @@ func RunHttpServer() {

listen := httpConf.Host + ":" + strconv.Itoa(int(httpConf.Port))

logger.Info("Started http server. "+listen, zap.Skip())
logger.Info("Started http server. " + listen)

httpServer = &http.Server{
Addr: listen,
Expand All @@ -35,6 +35,11 @@ func RunHttpServer() {
logger.Error(err.Error())
panic(err)
}

//监听进程结束时关闭服务
event.Listen("_stop", func(params any) {
HttpServerShutdown(params.(context.Context))
})
}

// GetHttpServer 获取http.Server实例
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ go 1.20

require (
github.com/gin-gonic/gin v1.9.0
github.com/go-gourd/gourd v0.2.4
go.uber.org/zap v1.24.0
github.com/go-gourd/gourd v0.2.6
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -25,12 +23,13 @@ require (
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
Expand All @@ -14,8 +12,6 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/go-gourd/gourd v0.2.4 h1:U5nZ1uJ3NAU4snzoEvGZmuZLC2xEPW04a9zpSIIZ/7s=
github.com/go-gourd/gourd v0.2.4/go.mod h1:laI9cGWfAEb3rbMZdfpzlblgs5/EKEvsVVCtayZwQ9E=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
Expand Down Expand Up @@ -50,8 +46,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us=
github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
8 changes: 8 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ghttp
import (
"github.com/gin-gonic/gin"
"github.com/go-gourd/gourd/config"
"github.com/go-gourd/gourd/event"
)

type routerHandler func(*gin.Engine)
Expand All @@ -24,6 +25,13 @@ func GetEngine() *gin.Engine {

ginEngine = gin.New()

//添加启动http服务事件监听
if config.GetHttpConfig().Enable {
event.Listen("_http_start", func(params any) {
go RunHttpServer()
})
}

return ginEngine
}

Expand Down

0 comments on commit ebcbde9

Please sign in to comment.