Exemplo n.º 1
0
func main() {
	r := gin.Default()
	r.LoadHTMLGlob("templates/*.tpl")

	// first create the auth handler
	conf := &ghauth.Conf{
		ClientId:     os.Getenv("GH_CLIENT_ID"),
		ClientSecret: os.Getenv("GH_CLIENT_SECRET"),
		Scopes:       []string{"user", "read:public_key", "repo"},
		CookieName:   "ghuser",
		CookieSecret: "any random string can go here, but make sure it is truly random and secret to secure your cookies",
	}
	auth := ghauth.New(conf)

	// register oauth routes
	auth.RegisterRoutes("/login", "/oauth", "/logout", r)
	r.Use(auth.AuthCheck())
	// all unauthorized routes can go here. Will still have user populated if logged in
	r.GET("/", home)

	// require authorization for these routes. Will redirect to login if not logged-in
	authRequired := r.Group("/", auth.RequireAuth())
	authRequired.GET("/repo/:owner/:repo", repo)

	r.Run(":8080") // listen and serve on 0.0.0.0:8080
}
Exemplo n.º 2
0
func main() {
	r := gin.Default()

	var err error
	useDev := os.Getenv("TEMPLE_DEV") != ""
	templateManager, err = temple.New(useDev, myTemplates, "templates")
	if err != nil {
		log.Fatal(err)
	}

	conf := &ghauth.Conf{
		ClientId:     os.Getenv("GITHUB_CLIENT_ID"),
		ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"),
		Scopes:       []string{"user", "repo"},
		CookieName:   "ghuser",
		CookieSecret: os.Getenv("COOKIE_SECRET"),
	}
	auth := ghauth.New(conf)
	auth.RegisterRoutes("/login", "/callback", "/logout", r)
	r.Use(renderError, auth.AuthCheck())
	r.StaticFS("/static", FS(useDev))
	r.GET("/", home)

	locked := r.Group("/", auth.RequireAuth())
	locked.GET("/repo/:owner/:repo", repo)
	locked.GET("/repo/:owner/:repo/:pr", pull)

	r.Run(":8765")
}
Exemplo n.º 3
0
func main() {
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/labelmaker/")
	viper.AddConfigPath(".")
	viper.SetDefault("RedisHost", "localhost:6379")
	viper.SetDefault("RedisDb", 1)
	var err error
	if err = viper.ReadInConfig(); err != nil {
		log.Fatal(err)
	}
	if err = viper.Unmarshal(&appConfig); err != nil {
		log.Fatal(err)
	}

	pool = newRedisPool(appConfig.RedisHost, appConfig.RedisDb)
	if templateManager, err = temple.New(appConfig.DevMode, templates, "templates"); err != nil {
		log.Fatal(err)
	}
	if !appConfig.DevMode {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.Default()
	conf := &ghauth.Conf{
		ClientId:     appConfig.GithubClientID,
		ClientSecret: appConfig.GithubClientSecret,
		Scopes:       []string{"user", "read:public_key", "repo"},
		CookieName:   "ghauth",
		CookieSecret: appConfig.CookieSecret,
	}
	auth := ghauth.New(conf)
	auth.RegisterRoutes("/login", "/callback", "/logout", r)
	r.Use(renderError)
	r.Use(auth.AuthCheck())

	r.GET("/", home)
	r.POST("/hooks/:hook", onHook)

	locked := r.Group("/", auth.RequireAuth())
	locked.GET("/repo/:owner/:name", repo)
	locked.POST("/install/:owner/:name", install)

	r.Run(":9999")
}