Beispiel #1
0
func RunRestApi(app gof.App, port int) {
	log.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)
	}
}
Beispiel #2
0
func Run(app gof.App, port int) {
	sto = app.Storage()
	API_DOMAIN = app.Config().GetString(variable.ApiDomain)
	log.Println("** [ Go2o][ API][ Booted] - Api server running on port " +
		strconv.Itoa(port))
	serve.Run(":" + strconv.Itoa(port)) //启动服务
}
Beispiel #3
0
// 运行网页
func RunWeb(app gof.App, port int, debug, trace bool) {

	if debug {
		log.Println("** [ Go2o][ Web][ Booted] - Web server (with debug) running on port " +
			strconv.Itoa(port))
		infrastructure.DebugMode = true
	} else {
		log.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)
	}
}