1 Star 0 Fork 3

xuguangmin/lmp

forked from zhoumeng/lmp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"lmp/logger"
"lmp/models"
"lmp/routes"
"lmp/settings"
"github.com/facebookgo/pidfile"
"go.uber.org/zap"
)
func showlogo() {
logo, err := ioutil.ReadFile("./misc/lmp.logo")
if err != nil {
fmt.Print(err)
}
fmt.Print(string(logo))
}
func main() {
showlogo()
pidfile.SetPidfilePath(os.Args[0] + ".pid")
pidfile.Write()
if err := settings.Init(); err != nil {
fmt.Println("Init settings failed, err:", err)
return
}
if err := logger.Init(settings.Conf.LogConfig, settings.Conf.AppConfig.Mode); err != nil {
fmt.Println("Init logger failed, err:", err)
return
}
defer zap.L().Sync()
/*
if err := influxdb.Init(settings.Conf.InfluxdbConfig); err != nil {
fmt.Println("Init influxdb failed, err:", err)
return
}
*/
bpfscan := &models.BpfScan{}
if err := bpfscan.Init(); err != nil {
fmt.Println("Init bpfscan failed, err:", err)
}
bpfscan.Run()
bpfscan.Watch()
r := routes.SetupRouter(settings.Conf.AppConfig.Mode)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", settings.Conf.AppConfig.Port),
Handler: r,
}
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
zap.L().Error("listen failed :", zap.Error(err))
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
zap.L().Info("shutdown server ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
zap.L().Error("Server shutdown", zap.Error(err))
}
zap.L().Info("Server exiting")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xugmin/lmp.git
git@gitee.com:xugmin/lmp.git
xugmin
lmp
lmp
master

搜索帮助