Commit 9a0f9fdb by lixinming

config & http

parent 74a4070e
package main
import (
"fmt"
"gaoqiaoCJY/src/db"
"os"
"os/signal"
"syscall"
"go.mongodb.org/mongo-driver/bson"
"gaoqiaoCJY/src/config"
"gaoqiaoCJY/src/server"
)
func exitProcess() {
fmt.Println("等待进程完成")
db.Exit_DB()
fmt.Println("进程退出")
os.Exit(-1)
}
func main() {
signals := make(chan os.Signal, 4)
done := make(chan bool, 1)
signal.Notify(signals, syscall.SIGILL, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT)
go func() {
for signal := range signals {
switch signal {
case syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT:
fmt.Println("kill -15 进程退出")
exitProcess()
case syscall.SIGILL:
fmt.Println("kill -4")
}
}
done <- true
}()
defer func() {
db.Exit_DB()
}()
fmt.Println("\r\n===============读取创业能力题库=================")
e := &db.Entrepreneurship{}
filter0 := bson.M{"id": 100}
entrepreneurships := []db.Entrepreneurship{}
err := e.GetList(filter0, entrepreneurships)
if err == nil {
for _, v := range entrepreneurships {
fmt.Println(v)
}
}
fmt.Println("\r\n===============读取创业能力题库=================")
config.InitConfig()
//xml do
server.CreateHttpServer()
//http
//异常
//log
//mongodb
//excel
//中间件
}
// func test() {
// fmt.Println("\r\n===============读取创业能力题库=================")
// e := &db.Entrepreneurship{}
// filter0 := bson.M{"id": 100}
// entrepreneurships := []db.Entrepreneurship{}
// err := e.GetList(filter0, entrepreneurships)
// if err == nil {
// for _, v := range entrepreneurships {
// fmt.Println(v)
// }
// }
// fmt.Println("\r\n===============读取创业能力题库=================")
// }
<config>
<port>30088</port>
<dbConfig>
<mongodbConnectionStr>
http://sfsdfasdfasfasd
</mongodbConnectionStr>
</dbConfig>
</config>
\ No newline at end of file
package config
import (
"encoding/xml"
"fmt"
"io/ioutil"
)
type MongodbConfig struct {
// Flag string `xml:"flag,attr"` // 读取flag属性
MongodbConnectionStr string `xml:"mongodbConnectionStr"` // 读取user数组
}
type ServerConfig struct {
Port string `xml:"port"`
DbConfig MongodbConfig `xml:"dbConfig"`
}
var SystemConfig ServerConfig
func InitConfig() {
fmt.Printf("---")
configByte, err := ioutil.ReadFile("./serverConfig.xml") //todo 路径需要改
if err != nil {
fmt.Printf(err.Error()) //todo 等待日志异常接入
}
err = xml.Unmarshal(configByte, &SystemConfig)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(SystemConfig)
}
}
package server
import (
"gaoqiaoCJY/src/config"
"gaoqiaoCJY/src/console"
"gaoqiaoCJY/src/router"
"github.com/gin-gonic/gin"
)
func CreateHttpServer(addr string) *gin.Engine {
func CreateHttpServer() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
......@@ -16,6 +17,8 @@ func CreateHttpServer(addr string) *gin.Engine {
//静态文件服务器
router.AddStaticFileServer(r, "public")
addr := config.SystemConfig.Port
console.Log("服务器监听地址", addr, "静态文件目录 ./public")
err := r.Run(addr)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment