mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Add default page Fixes #91
This commit is contained in:
parent
2040dbaaa5
commit
d481145c5f
@ -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")
|
||||
|
7
main.go
7
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",
|
||||
|
Loading…
Reference in New Issue
Block a user