Beispiel #1
0
func main() {
	migrate := flag.String("migrate", "skip", "Run DB migrations: up, down, redo, new [MIGRATION_NAME] and then os.Exit(0)")
	mode := flag.String("mode", "debug", "Application mode: debug, release, test")
	flag.Parse()

	shared.SetMode(mode)
	shared.Init()
	shared.RunMigrations(migrate)

	//Periodic tasks
	gocron.Every(1).Day().Do(shared.CreateXMLSitemap)
	gocron.Start()

	routes.Init()

	log.Printf("Listening on :%d port in %q mode\n", 8080, *mode)
	log.Fatal(http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux)))
}
Beispiel #2
0
func main() {
	migration := flag.String("migrate", "", "Run DB migrations: up, down, redo, new [MIGRATION_NAME] and then os.Exit(0)")
	flag.Parse()

	setLogger()
	loadConfig()
	connectToDB()
	runMigrations(migration)

	//Periodic tasks
	gocron.Every(1).Day().Do(system.CreateXMLSitemap)
	gocron.Start()

	// Creates a gin router with default middleware:
	// logger and recovery (crash-free) middleware
	router := gin.Default()
	setTemplate(router) //initialize templates
	setSessions(router) //initialize session storage & use sessiom/csrf middlewares

	router.StaticFS("/public", http.Dir(system.PublicPath())) //better use nginx to serve assets (Cache-Control, Etag, fast gzip, etc)
	router.Use(SharedData())

	router.GET("/", controllers.HomeGet)
	router.NoRoute(controllers.NotFound)
	router.NoMethod(controllers.MethodNotAllowed)

	if system.GetConfig().SignupEnabled {
		router.GET("/signup", controllers.SignUpGet)
		router.POST("/signup", controllers.SignUpPost)
	}
	router.GET("/signin", controllers.SignInGet)
	router.POST("/signin", controllers.SignInPost)
	router.GET("/logout", controllers.LogoutGet)

	router.GET("/pages/:id", controllers.PageGet)
	router.GET("/posts/:id", controllers.PostGet)
	router.GET("/tags/:name", controllers.TagGet)
	router.GET("/archives/:year/:month", controllers.ArchiveGet)
	router.GET("/rss", controllers.RssGet)

	authorized := router.Group("/admin")
	authorized.Use(AuthRequired())
	{
		authorized.GET("/", controllers.AdminGet)

		authorized.POST("/upload", controllers.UploadPost) //image upload

		authorized.GET("/users", controllers.UserIndex)
		authorized.GET("/new_user", controllers.UserNew)
		authorized.POST("/new_user", controllers.UserCreate)
		authorized.GET("/users/:id/edit", controllers.UserEdit)
		authorized.POST("/users/:id/edit", controllers.UserUpdate)
		authorized.POST("/users/:id/delete", controllers.UserDelete)

		authorized.GET("/pages", controllers.PageIndex)
		authorized.GET("/new_page", controllers.PageNew)
		authorized.POST("/new_page", controllers.PageCreate)
		authorized.GET("/pages/:id/edit", controllers.PageEdit)
		authorized.POST("/pages/:id/edit", controllers.PageUpdate)
		authorized.POST("/pages/:id/delete", controllers.PageDelete)

		authorized.GET("/posts", controllers.PostIndex)
		authorized.GET("/new_post", controllers.PostNew)
		authorized.POST("/new_post", controllers.PostCreate)
		authorized.GET("/posts/:id/edit", controllers.PostEdit)
		authorized.POST("/posts/:id/edit", controllers.PostUpdate)
		authorized.POST("/posts/:id/delete", controllers.PostDelete)

		authorized.GET("/tags", controllers.TagIndex)
		authorized.GET("/new_tag", controllers.TagNew)
		authorized.POST("/new_tag", controllers.TagCreate)
		authorized.POST("/tags/:name/delete", controllers.TagDelete)
	}

	// Listen and server on 0.0.0.0:8080
	router.Run(":8080")
}
Beispiel #3
0
func main() {
	mode := flag.String("mode", "debug", "Application mode: debug, release, test")
	flag.Parse()

	system.SetMode(mode)
	system.Init()

	//Periodic tasks
	if system.GetMode() == system.ReleaseMode {
		system.CreateXMLSitemap() //refresh sitemap now
	}
	gocron.Every(1).Day().Do(system.CreateXMLSitemap) //refresh daily
	gocron.Start()

	gin.SetMode(system.GetMode())
	router := gin.Default()
	store := sessions.NewCookieStore([]byte(system.GetConfig().SessionSecret))
	router.Use(sessions.Sessions("gin-session", store))
	router.SetHTMLTemplate(system.GetTemplates())
	router.GET("/", controllers.Home)
	router.StaticFS("/public", http.Dir("public"))
	router.GET("/signin", controllers.SignInGet)
	router.POST("/signin", controllers.SignInPost)
	router.GET("/logout", controllers.LogOut)
	if system.GetConfig().SignupEnabled {
		router.GET("/signup", controllers.SignUpGet)
		router.POST("/signup", controllers.SignUpPost)
	}

	router.GET("/pages/:idslug", controllers.PageShow)
	router.GET("/articles", controllers.ArticlesIndex)
	router.GET("/articles/:idslug", controllers.ArticleShow)
	router.GET("/reviews", controllers.ReviewsIndex)
	router.GET("/reviews/:id", controllers.ReviewShow)
	router.POST("/new_request", controllers.RequestCreatePost)
	router.POST("/new_comment", controllers.CommentCreatePost)
	//http.Handle("/edit_comment", Default(controllers.CommentPublicUpdate))
	router.GET("/new_review", controllers.ReviewCreateGet)
	router.POST("/new_review", controllers.ReviewCreatePost)
	router.GET("/edit_review", controllers.ReviewUpdateGet)
	router.POST("/edit_review", controllers.ReviewUpdatePost)

	router.Use(system.Authenticated())
	{
		router.GET("/admin", controllers.Dashboard)
		router.GET("/admin/users", controllers.UsersAdminIndex)
		router.GET("/admin/new_user", controllers.UserAdminCreateGet)
		router.POST("/admin/new_user", controllers.UserAdminCreatePost)
		router.GET("/admin/edit_user/:id", controllers.UserAdminUpdateGet)
		router.POST("/admin/edit_user/:id", controllers.UserAdminUpdatePost)
		router.POST("/admin/delete_user", controllers.UserAdminDelete)

		router.GET("/admin/pages", controllers.PagesAdminIndex)
		router.GET("/admin/new_page", controllers.PageAdminCreateGet)
		router.POST("/admin/new_page", controllers.PageAdminCreatePost)
		router.GET("/admin/edit_page/:id", controllers.PageAdminUpdateGet)
		router.POST("/admin/edit_page/:id", controllers.PageAdminUpdatePost)
		router.POST("/admin/delete_page", controllers.PageAdminDelete)

		router.GET("/admin/articles", controllers.ArticlesAdminIndex)
		router.GET("/admin/new_article", controllers.ArticleAdminCreateGet)
		router.POST("/admin/new_article", controllers.ArticleAdminCreatePost)
		router.GET("/admin/edit_article/:id", controllers.ArticleAdminUpdateGet)
		router.POST("/admin/edit_article/:id", controllers.ArticleAdminUpdatePost)
		router.POST("/admin/delete_article", controllers.ArticleAdminDelete)

		router.GET("/admin/comments", controllers.CommentsAdminIndex)
		router.GET("/admin/edit_comment/:id", controllers.CommentAdminUpdateGet)
		router.POST("/admin/edit_comment/:id", controllers.CommentAdminUpdatePost)
		router.POST("/admin/delete_comment", controllers.CommentAdminDelete)

		router.GET("/admin/reviews", controllers.ReviewsAdminIndex)
		router.GET("/admin/new_review", controllers.ReviewAdminCreateGet)
		router.POST("/admin/new_review", controllers.ReviewAdminCreatePost)
		router.GET("/admin/edit_review/:id", controllers.ReviewAdminUpdateGet)
		router.POST("/admin/edit_review/:id", controllers.ReviewAdminUpdatePost)
		router.POST("/admin/delete_review", controllers.ReviewAdminDelete)

		router.POST("/admin/ckupload", controllers.CkUpload)
	}

	log.Fatal(router.Run(":8010"))
}