init
This commit is contained in:
46
comet/http/server.go
Normal file
46
comet/http/server.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user