Exemplo n.º 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())
	}
}
Exemplo n.º 2
0
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())
	}
}
Exemplo n.º 3
0
func (this dispatchAction) Run(vars map[string]interface{}, next func()) {
	actions := rack.New()
	actions.Add(this.action)
	switch (httper.V)(vars).GetRequest().Method {
	case "GET":
		//if it was a get, the default action should be to render the template corresponding with the action
		actions.Add(renderer.Renderer{this.routeName + "/" + this.name})
	case "POST", "PUT":
		//if it was a put or a post, we the default action should be to redirect to the affected item
		actions.Add(rack.Func(func(vars map[string]interface{}, next func()) {
			urler, isUrler := vars[this.varName].(Urler)
			if !isUrler {
				panic("Object doesn't have an URL to direct to")
			}
			(redirecter.V)(vars).Redirect(urler.Url())
		}))
	case "DELETE":
		//I'm not currently sure what the default action for deletion should be, perhaps redirecting to the parent route
	default:
		panic("Unknown method")
	}
	actions.Run(vars, next)
}