This commit is contained in:
2022-03-17 15:55:27 +08:00
commit bd5a9fad97
92 changed files with 13861 additions and 0 deletions

46
comet/http/server.go Normal file
View File

@@ -0,0 +1,46 @@
package http
import (
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"gitlab.33.cn/chat/im/comet"
"gitlab.33.cn/chat/im/comet/conf"
"net/http"
)
var (
srv *comet.Comet
)
func Start(addr string, s *comet.Comet) *http.Server {
srv = s
gin.ForceConsoleColor()
switch conf.Conf.Env {
case conf.DebugMode:
gin.SetMode(gin.DebugMode)
case conf.ReleaseMode:
gin.SetMode(gin.ReleaseMode)
}
engine := gin.Default()
SetupEngine(engine)
pprof.Register(engine)
srv := &http.Server{
Addr: addr,
Handler: engine,
}
go func() {
// service connections
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatal().Err(err).Msg("http listen failed")
}
}()
return srv
}
func SetupEngine(e *gin.Engine) *gin.Engine {
e.GET("/statics", Statics)
e.GET("/groupDetails", GroupDetails)
return e
}