Пример #1
0
func main() {

	//setup sessions
	/*
		sh := redis.NewSessionHolder()
		redisconfig := viper.GetStringMapString("redis")
		if _, ok := redisconfig["host"]; !ok {
			panic("failed to read redis host")
		}
		if _, ok := redisconfig["port"]; !ok {
			panic("failed to read redis port")
		}

		redisip, err := alias2ipaddr(redisconfig["host"])
		if err != nil {
			panic("failed to lookup redis IP address")
		}
		goji.Use(redis.BuildRedis(fmt.Sprintf("%s:%s", redisip, redisconfig["port"])))
		goji.Use(base.BuildSessionMiddleware(sh))
	*/

	c := cors.New(cors.Options{
		AllowedOrigins: []string{"*"},
	})
	goji.Use(c.Handler)

	//setup render middleware
	goji.Use(middleware.RenderMiddleware)

	//setup database
	/*
		dbconfig := viper.GetStringMapString("db")
		if _, ok := dbconfig["host"]; !ok {
			panic("failed to read db host")
		}
		if _, ok := dbconfig["name"]; !ok {
			panic("failed to read db name")
		}
		goji.Use(middleware.PostgresMiddleware)

		goji.Use(middleware.AuthMiddleware)
	*/

	//setup routes
	goji.Get("/home", controllers.IndexHandler)
	goji.Get("/healthcheck", controllers.HealthCheckHandler)
	goji.Get("/login", controllers.Login)
	goji.Get("/oauth2callback", controllers.OAuth2Callback)
	//goji.Get("/logout", controllers.Logout)

	//setup static assets
	goji.Use(gojistatic.Static("/go/src/bower_components", gojistatic.StaticOptions{SkipLogging: true, Prefix: "bower_components"}))
	goji.Use(gojistatic.Static("/go/src/frontend/js", gojistatic.StaticOptions{SkipLogging: true, Prefix: "js"}))

	//begin
	log.Info("Starting App...")

	flag.Set("bind", ":80")
	goji.Serve()
}
Пример #2
0
func main() {
	extdirect.Provider.RegisterAction(reflect.TypeOf(Db{}))
	goji.Get(extdirect.Provider.URL, extdirect.API(extdirect.Provider))
	goji.Post(extdirect.Provider.URL, func(c web.C, w http.ResponseWriter, r *http.Request) {
		extdirect.ActionsHandlerCtx(extdirect.Provider)(gcontext.FromC(c), w, r)
	})
	goji.Use(gojistatic.Static("public", gojistatic.StaticOptions{SkipLogging: true}))
	goji.Serve()
}
Пример #3
0
func main() {
	// setup static
	goji.Use(gojistatic.Static("public",
		gojistatic.StaticOptions{SkipLogging: true}))

	// app routing
	Route(goji.DefaultMux)

	// start server
	goji.Serve()
}
Пример #4
0
func main() {
	// Serve static files
	goji.Use(gojistatic.Static("public", gojistatic.StaticOptions{SkipLogging: true}))

	// Add routes
	routes.Include()

	trigger := make(chan bool)
	startTrending := make(chan bool)
	tickerChan := time.NewTicker(time.Minute * 10).C
	tickerTrending := time.NewTicker(time.Minute * 10).C

	// Update data from BigQuery
	go func() {
		for {
			select {
			case <-trigger:
				models.Update()
			case <-tickerChan:
				models.Update()
			}
		}
	}()

	// Update Github trending repos
	go func() {
		for {
			select {
			case <-startTrending:
				models.UpdateGithubTrendingRepos()
			case <-tickerTrending:
				models.UpdateGithubTrendingRepos()
			}
		}
	}()

	trigger <- true
	startTrending <- true

	// Run Goji
	goji.Serve()
}