示例#1
0
func main() {

	//set up the models
	model.SetUp() //can't happen during models's init, because it needs to wait until each of the models has initialized

	//set up the interceptor routes
	cept := interceptor.New()

	//facebook
	fb := login.NewFacebooker(LoadFacebookData())
	oauther.SetIntercepts(cept, fb, login.HandleToken)

	//google plus
	gp := login.NewGooglePlusser(LoadGoogleData())
	oauther.SetIntercepts(cept, gp, login.HandleToken)

	//logging out
	cept.Intercept("/logout/", login.LogOut)

	//load the templates for the views
	templater.LoadFromFiles("./views", log.New(os.Stdout, "template - ", log.LstdFlags))

	ws := websocketcontrol.New()

	//set up the rack
	rackup := rack.New()
	rackup.Add(logger.Set(os.Stdout, "Log Test - ", log.LstdFlags))
	rackup.Add(requestlogger.M)
	rackup.Add(staticer.New("/static/", "static"))
	rackup.Add(varser.Default{"Layout": "base"})
	rackup.Add(randomer{})
	rackup.Add(encapsulator.AddLayout)
	rackup.Add(statuser.SetErrorLayout)
	if constants.Mode != constants.Debug {
		rackup.Add(errorhandler.ErrorHandler) //in debug version, it's more useful to just let it crash, so we can get more error information
	}
	rackup.Add(sessioner.Middleware)
	rackup.Add(login.Middleware)
	rackup.Add(ws)
	rackup.Add(parser.Form)
	rackup.Add(methoder.Override)
	rackup.Add(cept)
	rackup.Add(clashgetter.QueueGetter)
	rackup.Add(controllers.Root)

	//alert the user as to where we are running

	fmt.Print("\n\nStarting at " + constants.Site + "!\n\n\n")
	conn := httper.HttpConnection(constants.Port)
	err := conn.Go(rackup)

	//We're ready to go!
	//run each request through the rack!
	if err != nil {
		fmt.Print("Error: " + err.Error())
	}
}
示例#2
0
文件: main.go 项目: koomee/TestGame
func main() {
	templater.LoadFromFiles("views", nil)
	g := singleton.Get()

	rackup := rack.New()
	rackup.Add(Debugger)
	if isDispatcher {
		rackup.Add(parser.Form)
		cept := interceptor.New()
		cept.Intercept(g.CommUrl(), GameQuery{wrapper.Game{g}})
		rackup.Add(cept)
	}
	if isGameServer {
		rackup.Add(staticer.New("/", "static"))
		//		rackup.Add(sessioner.Middleware)
		rackup.Add(randomer{})
		rackup.Add(PlayerGetter(g))
		rackup.Add(GameAction(g))
		rackup.Add(Renderer)
	}

	var base string
	var port string
	if debugMode {
		base = "localhost"
		port = ":3001"
	} else {
		base = "108.166.123.13"
		port = ":80"
	}

	if isGameServer {
		server.AddServerCapacity("http://"+base+port, 100) //room for 100 games
	}

	conn := httper.HttpConnection(port)
	fmt.Println("Starting Server - use " + base + port + g.CommUrl())
	err := conn.Go(rackup)
	if err != nil {
		fmt.Println("Error:" + err.Error())
	}
}