示例#1
0
文件: web_server.go 项目: honj51/go2o
// 运行网页
func RunWeb(app gof.App, port int, debug, trace bool) {

	if debug {
		fmt.Println("[Started]:Web server (with debug) running on port [" +
			strconv.Itoa(port) + "]:")
		infrastructure.DebugMode = true
	} else {
		fmt.Println("[Started]:Web server running on port [" + strconv.Itoa(port) + "]:")
	}

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)
	goclient.Configure("tcp", app.Config().GetString(variable.ClientSocketServer), app)

	var in = getInterceptor(app)

	//注册路由
	RegisterRoutes(app)

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}
示例#2
0
func RunRestApi(app gof.App, port int) {
	fmt.Println("[ Go2o][ API][ Booted] - Api server running on port " + strconv.Itoa(port))

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)
	goclient.Configure("tcp", app.Config().GetString(variable.ClientSocketServer), app)

	var in *web.Interceptor = web.NewInterceptor(app, func(ctx *web.Context) {
		host := ctx.Request.URL.Host
		// todo: path compare
		if API_HOST_CHK && host != API_DOMAIN {
			http.Error(ctx.Response, "no such file", http.StatusNotFound)
			return
		}
		api.Handle(ctx)
	})

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}
示例#3
0
// 运行网页
func RunWeb(app gof.App, port int, debug, trace bool) {

	if debug {
		fmt.Println("[ Go2o][ Web][ Booted] - Web server (with debug) running on port " +
			strconv.Itoa(port))
		infrastructure.DebugMode = true
	} else {
		fmt.Println("[ Go2o][ Web][ Booted] - Web server running on port " + strconv.Itoa(port))
	}

	//socket client
	time.Sleep(time.Second * 2) //等待启动Socket
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)

	var in = getInterceptor(app)

	//启动服务
	err := http.ListenAndServe(":"+strconv.Itoa(port), in)

	if err != nil {
		app.Log().Fatalln("ListenAndServer ", err)
	}
}