Пример #1
0
func Run() {
	// 开启最大核心数运行
	runtime.GOMAXPROCS(runtime.NumCPU())

	// 预绑定路由
	Router()
	// 开启websocket
	go func() {
		reporter.Println("[pholcus] websocket server Running on ", wsAddr)
		if err := http.ListenAndServe(wsAddr, nil); err != nil {
			reporter.Fatal("Websocket ListenAndServe: ", err)
		}
	}()
	// 开启websocket log
	go func() {
		reporter.Println("[pholcus] websocket log server Running on ", wslogAddr)
		if err := http.ListenAndServe(wslogAddr, nil); err != nil {
			reporter.Fatal("Websocket Log ListenAndServe: ", err)
		}
	}()
	// 开启http
	reporter.Println("[pholcus] http server Running on ", addr)
	err := http.ListenAndServe(addr, nil) //设置监听的端口
	if err != nil {
		reporter.Fatal("Http ListenAndServe: ", err)
	}
}
Пример #2
0
func Run() {
	// 开启最大核心数运行
	runtime.GOMAXPROCS(runtime.NumCPU())

	// 预绑定路由
	Router()
	// 监听端口
	reporter.Println("[pholcus] server Running on ", addr)
	err := http.ListenAndServe(addr, nil) //设置监听的端口
	if err != nil {
		reporter.Fatal("ListenAndServe: ", err)
	}
}
Пример #3
0
func Run() {
	// 预绑定路由
	Router()
	// 开启websocket
	go func() {
		reporter.Println("[pholcus] websocket server Running on ", wsport)
		if err := http.ListenAndServe(wsport, nil); err != nil {
			reporter.Fatal("Websocket ListenAndServe: ", err)
		}
	}()
	// 开启websocket log
	go func() {
		reporter.Println("[pholcus] websocket log server Running on ", wslogport)
		if err := http.ListenAndServe(wslogport, nil); err != nil {
			reporter.Fatal("Websocket Log ListenAndServe: ", err)
		}
	}()
	// 开启http
	reporter.Println("[pholcus] http server Running on ", webport)
	err := http.ListenAndServe(webport, nil) //设置监听的端口
	if err != nil {
		reporter.Fatal("Http ListenAndServe: ", err)
	}
}
Пример #4
0
// 处理web页面请求
func pholcus(rw http.ResponseWriter, req *http.Request) {
	t, err := template.ParseFiles("web/views/index.html") //解析模板文件
	if err != nil {
		reporter.Println(err)
	}
	//获取pholcus信息
	data := map[string]interface{}{
		"title":   config.APP_NAME,
		"logo":    config.ICON_PNG,
		"version": config.APP_VERSION,
		"author":  config.APP_AUTHOR,
		"mode": map[string]int{
			"offline": status.OFFLINE,
			"server":  status.SERVER,
			"client":  status.CLIENT,
			"default": defaultConfig.RunMode,
		},
		"port": defaultConfig.Port,
		"ip":   defaultConfig.Master,
	}
	t.Execute(rw, data) //执行模板的merger操作
}