From d481145c5f71ab9ce4bcb886569b6ab124fa845b Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 4 Nov 2017 04:21:51 -0600 Subject: [PATCH] Add default page Fixes #91 --- handlers.go | 8 ++++++-- main.go | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/handlers.go b/handlers.go index 445c7c6..6020a59 100755 --- a/handlers.go +++ b/handlers.go @@ -19,7 +19,7 @@ import ( var customCSS []byte -func serve(host, port, crt_path, key_path string, TLS bool, cssFile string) { +func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string) { gin.SetMode(gin.ReleaseMode) router := gin.Default() store := sessions.NewCookieStore([]byte("secret")) @@ -27,7 +27,11 @@ func serve(host, port, crt_path, key_path string, TLS bool, cssFile string) { router.HTMLRender = loadTemplates("index.tmpl") // router.Use(static.Serve("/static/", static.LocalFile("./static", true))) router.GET("/", func(c *gin.Context) { - c.Redirect(302, "/"+randomAlliterateCombo()) + if defaultPage != "" { + c.Redirect(302, "/"+defaultPage+"/read") + } else { + c.Redirect(302, "/"+randomAlliterateCombo()) + } }) router.GET("/:page", func(c *gin.Context) { page := c.Param("page") diff --git a/main.go b/main.go index 1c46a93..4bbe4b3 100755 --- a/main.go +++ b/main.go @@ -38,7 +38,7 @@ func main() { } else { fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port")) } - serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css")) + serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page")) return nil } app.Flags = []cli.Flag{ @@ -77,6 +77,11 @@ func main() { Value: "", Usage: "use a custom CSS file", }, + cli.StringFlag{ + Name: "default-page", + Value: "", + Usage: "show default-page/read instead of editing", + }, cli.BoolFlag{ Name: "debug, d", Usage: "turn on debugging",