예제 #1
0
파일: main.go 프로젝트: captncraig/squasher
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")
}
예제 #2
0
파일: main.go 프로젝트: captncraig/temple
func main() {
	flag.Parse()
	templateManager, err := temple.New(*devMode, myTemplates, "templates")
	if err != nil {
		log.Fatal(err)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		ctx := homePageContext{
			baseContext{"Home"},
			[]string{"foo", "bar", "baz"},
		}
		// homepage composes shared templates by directly referencing "header" and "footer" templates.
		err := templateManager.Execute(w, ctx, "homepage")
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
	})

	http.HandleFunc("/mc", func(w http.ResponseWriter, r *http.Request) {
		ctx := masterChildContext{
			baseContext{"Master / Child"},
			"AAAAA",
			"BBBBB",
		}
		// master / child templates let the library compose things for you
		// so no explicit reference to other templates is needed.
		err := templateManager.ExecuteMaster(w, ctx, "master", "child")
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
	})
	http.ListenAndServe(":5555", nil)

}
예제 #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")
}