Example #1
0
func App() *gin.Engine {

	app := gin.Default()

	//middleware
	app.Use(video.Middleware())
	app.Use(staticjsx.NewStaticjsx("jsx", false).ServeHTTP)

	//routes
	app.GET("/", video.ListVideo)
	app.GET("/view/:file", video.ViewVideo)
	app.POST("/upload", video.UploadVideo)
	app.GET("/video/:file", video.StreamVideo)
	app.POST("/video/description", video.VideoDescription)
	app.GET("/videoList", video.VideoListRequest)
	app.GET("/videoList/video/:title", video.VideoByTitleRequest)

	//authenticated routes
	cfg := config.ReadConfig()
	var accounts gin.Accounts = make(map[string]string)
	accounts[cfg.AdminUsername] = cfg.AdminPassword
	g := app.Group("/admin", gin.BasicAuth(accounts))
	g.DELETE("/video/:title", video.VideoDelete)

	//templates
	app.LoadHTMLGlob("templates/*")

	//static files
	app.Static("/public", "./public")

	return app
}
Example #2
0
func CreateDatabaseSession() *sql.DB {
	//check for database env variable
	dbUrl := os.Getenv("DATABASE_URL")
	//otherwise use config file
	if dbUrl == "" {
		cfg := config.ReadConfig()
		dbUrl = cfg.DatabaseUrl
	}
	log.Println("Connecting to Database: " + dbUrl)
	db, err := sql.Open("postgres", dbUrl)
	if err != nil {
		log.Fatal(err)
	}

	return db
}