sysInfo增加LocalIP字段

This commit is contained in:
dexter
2022-07-17 09:36:27 +08:00
parent ec5f8b0214
commit 935cd73f0d
2 changed files with 16 additions and 19 deletions

17
main.go
View File

@@ -5,10 +5,12 @@ import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/google/uuid"
@@ -21,11 +23,15 @@ import (
)
var (
SysInfo struct {
StartTime time.Time //启动时间
LocalIP string
Version string
}
ExecPath = os.Args[0]
ExecDir = filepath.Dir(ExecPath)
// ConfigRaw 配置信息的原始数据
ConfigRaw []byte
StartTime time.Time //启动时间
Plugins = make(map[string]*Plugin) // Plugins 所有的插件配置
EngineConfig = &GlobalConfig{
Engine: config.Global,
@@ -37,9 +43,16 @@ var (
apiList []string //注册到引擎的API接口列表
)
func init() {
if conn, err := net.Dial("udp", "114.114.114.114:80"); err == nil {
SysInfo.LocalIP, _, _ = strings.Cut(conn.LocalAddr().String(), ":")
}
}
// Run 启动Monibuca引擎传入总的Context可用于关闭所有
func Run(ctx context.Context, configFile string) (err error) {
StartTime = time.Now()
SysInfo.StartTime = time.Now()
SysInfo.Version = Engine.Version
Engine.Context = ctx
if _, err := os.Stat(configFile); err != nil {
configFile = filepath.Join(ExecDir, configFile)