feat: 合并Gin_Vue
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"ems.agt/lib/core/conf"
|
||||
"ems.agt/lib/global"
|
||||
"ems.agt/lib/log"
|
||||
|
||||
@@ -288,7 +286,7 @@ func GetLogLevel() log.LogLevel {
|
||||
|
||||
var (
|
||||
DefaultUriPrefix string = "/api/rest"
|
||||
UriPrefix string = "/api/rest"
|
||||
UriPrefix string = "/omc/rest"
|
||||
//TestDataUDM []map[string]interface{}
|
||||
TDatas map[string]NeTestData
|
||||
)
|
||||
@@ -312,33 +310,33 @@ func GetDefaultUserAgent() string {
|
||||
return "OMC-restagent/" + global.Version
|
||||
}
|
||||
|
||||
const defaultConfigFile = "./etc/restconf.yaml"
|
||||
// const defaultConfigFile = "./etc/restconf.yaml"
|
||||
|
||||
func init() {
|
||||
cfile := flag.String("c", defaultConfigFile, "config file")
|
||||
pv := flag.Bool("version", false, "print version")
|
||||
ph := flag.Bool("help", false, "print help")
|
||||
// func init() {
|
||||
// cfile := flag.String("c", defaultConfigFile, "config file")
|
||||
// pv := flag.Bool("version", false, "print version")
|
||||
// ph := flag.Bool("help", false, "print help")
|
||||
|
||||
//global.BuildTime = "Wed May 31 18:24:04 CST 2023"
|
||||
//global.GoVer = "go version go1.15.7 linux/arm64"
|
||||
flag.Parse()
|
||||
if *pv {
|
||||
fmt.Printf("OMC restagent version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
|
||||
os.Exit(0)
|
||||
}
|
||||
if *ph {
|
||||
flag.Usage()
|
||||
os.Exit(0)
|
||||
}
|
||||
// //global.BuildTime = "Wed May 31 18:24:04 CST 2023"
|
||||
// //global.GoVer = "go version go1.15.7 linux/arm64"
|
||||
// flag.Parse()
|
||||
// if *pv {
|
||||
// fmt.Printf("OMC restagent version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
|
||||
// os.Exit(0)
|
||||
// }
|
||||
// if *ph {
|
||||
// flag.Usage()
|
||||
// os.Exit(0)
|
||||
// }
|
||||
|
||||
// 使用viper读取配置
|
||||
conf.InitConfig(*cfile)
|
||||
// // 使用viper读取配置
|
||||
// conf.InitConfig(*cfile)
|
||||
|
||||
ReadConfig(*cfile)
|
||||
if GetYamlConfig().OMC.UriPrefix != "" {
|
||||
UriPrefix = GetYamlConfig().OMC.UriPrefix
|
||||
}
|
||||
if GetYamlConfig().TestConfig.Enabled {
|
||||
ReadTestConfigYaml(GetYamlConfig().TestConfig.File)
|
||||
}
|
||||
}
|
||||
// ReadConfig(*cfile)
|
||||
// if GetYamlConfig().OMC.UriPrefix != "" {
|
||||
// UriPrefix = GetYamlConfig().OMC.UriPrefix
|
||||
// }
|
||||
// if GetYamlConfig().TestConfig.Enabled {
|
||||
// ReadTestConfigYaml(GetYamlConfig().TestConfig.File)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -4,24 +4,23 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ems.agt/lib/core/redis"
|
||||
"ems.agt/features/dbrest"
|
||||
"ems.agt/features/fm"
|
||||
"ems.agt/features/lm"
|
||||
"ems.agt/features/pm"
|
||||
"ems.agt/lib/dborm"
|
||||
"ems.agt/lib/global"
|
||||
"ems.agt/lib/log"
|
||||
"ems.agt/lib/routes"
|
||||
|
||||
"ems.agt/features/dbrest"
|
||||
"ems.agt/features/fm"
|
||||
"ems.agt/features/lm"
|
||||
"ems.agt/features/monitor/monitor"
|
||||
"ems.agt/features/pm"
|
||||
"ems.agt/restagent/config"
|
||||
"ems.agt/src"
|
||||
libSession "ems.agt/src/lib_features/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// const defaultConfigFile = "./etc/restconf.yaml"
|
||||
@@ -46,25 +45,25 @@ import (
|
||||
// //fmt.Println(config.UriPrefix)
|
||||
// }
|
||||
|
||||
func listenIPv6(ipv6 string, port int) {
|
||||
//
|
||||
addr := &net.TCPAddr{
|
||||
IP: net.ParseIP(ipv6),
|
||||
Port: port,
|
||||
}
|
||||
// func listenIPv6(ipv6 string, port int) {
|
||||
// //
|
||||
// addr := &net.TCPAddr{
|
||||
// IP: net.ParseIP(ipv6),
|
||||
// Port: port,
|
||||
// }
|
||||
|
||||
listener, err := net.ListenTCP("tcp6", addr)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to listen:", err)
|
||||
return
|
||||
}
|
||||
// listener, err := net.ListenTCP("tcp6", addr)
|
||||
// if err != nil {
|
||||
// fmt.Println("Failed to listen:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
server := &http.Server{}
|
||||
err = server.Serve(listener)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to serve:", err)
|
||||
}
|
||||
}
|
||||
// server := &http.Server{}
|
||||
// err = server.Serve(listener)
|
||||
// if err != nil {
|
||||
// fmt.Println("Failed to serve:", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
func HttpListen(addr string, router http.Handler) {
|
||||
err := http.ListenAndServe(addr, router)
|
||||
@@ -128,6 +127,10 @@ func HttpListenWebServer(addr string) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// src 配置中心初始加载
|
||||
src.ConfigurationInit()
|
||||
app := src.AppEngine()
|
||||
|
||||
conf := config.GetYamlConfig()
|
||||
|
||||
log.InitLogger(conf.Logger.File, conf.Logger.Duration, conf.Logger.Count, "omc:restagent", config.GetLogLevel())
|
||||
@@ -166,22 +169,28 @@ func main() {
|
||||
os.Exit(4)
|
||||
}
|
||||
|
||||
// 连接redis
|
||||
redis.Connect()
|
||||
// 将 mux.Router 注册到 gin.Engine
|
||||
|
||||
router := routes.NewRouter()
|
||||
// 默认路由组
|
||||
defaultUriGroup := app.Group(config.DefaultUriPrefix)
|
||||
defaultUriGroup.Use(libSession.SessionHeader())
|
||||
defaultUriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
|
||||
// 可配置前缀路由组
|
||||
uriGroup := app.Group(config.UriPrefix)
|
||||
uriGroup.Use(libSession.SessionHeader())
|
||||
uriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
|
||||
|
||||
// 开启监控采集
|
||||
monitor.StartMonitor(false, "")
|
||||
// monitor.StartMonitor(false, "")
|
||||
|
||||
for _, rest := range conf.Rest {
|
||||
// ipv4 goroutines
|
||||
if rest.IPv4 != "" {
|
||||
listen := rest.IPv4 + ":" + strconv.Itoa(int(rest.Port))
|
||||
if strings.ToLower(rest.Scheme) == "https" {
|
||||
go HttpListenTLS(listen, rest.CertFile, rest.KeyFile, router)
|
||||
go HttpListenTLS(listen, rest.CertFile, rest.KeyFile, app)
|
||||
} else {
|
||||
go HttpListen(listen, router)
|
||||
go HttpListen(listen, app)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -189,9 +198,9 @@ func main() {
|
||||
if rest.IPv6 != "" {
|
||||
listenv6 := "[" + rest.IPv6 + "]" + ":" + strconv.Itoa(int(rest.Port))
|
||||
if strings.ToLower(rest.Scheme) == "https" {
|
||||
go HttpListenTLS(listenv6, rest.CertFile, rest.KeyFile, router)
|
||||
go HttpListenTLS(listenv6, rest.CertFile, rest.KeyFile, app)
|
||||
} else {
|
||||
go HttpListen(listenv6, router)
|
||||
go HttpListen(listenv6, app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user