50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
|
|
"github.com/NothAmor/SourceTraceFront/common"
|
|
"github.com/NothAmor/SourceTraceFront/router"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/smallnest/rpcx/client"
|
|
"github.com/smallnest/rpcx/protocol"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func main() {
|
|
// load config
|
|
initConfig()
|
|
|
|
// init gin core
|
|
common.Core = gin.Default()
|
|
|
|
// load static resource
|
|
common.Core.LoadHTMLGlob("views/*")
|
|
|
|
// init router
|
|
router.InitRouter()
|
|
|
|
// init rpc
|
|
d, _ := client.NewPeer2PeerDiscovery("tcp@"+*common.RPC_SERVER_ADDR, "")
|
|
opt := client.DefaultOption
|
|
opt.SerializeType = protocol.JSON
|
|
common.RPC = client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, opt)
|
|
defer common.RPC.Close()
|
|
|
|
// start server
|
|
common.Core.Run(fmt.Sprintf(":%d", common.Config.Sys.Port))
|
|
}
|
|
|
|
func initConfig() {
|
|
config, err := ioutil.ReadFile("config.yaml")
|
|
if err != nil {
|
|
panic("读取配置文件失败")
|
|
}
|
|
|
|
err = yaml.Unmarshal(config, &common.Config)
|
|
if err != nil {
|
|
panic("解析配置文件失败")
|
|
}
|
|
}
|