1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

New: Make host configurable, Fix #69

Former-commit-id: e087e6952610f7baeb212e12cef44eafcb06613d
This commit is contained in:
Zack Scholl 2017-03-28 08:01:03 -06:00
parent 86c86779dd
commit 23536ad927
3 changed files with 14 additions and 5 deletions

View File

@ -33,7 +33,7 @@ To run just double click or from the command line:
cowyo cowyo
``` ```
and it will start a server listening on `0.0.0.0:8050`. To view it, just go to http://localhost:8050 (the server prints out the local IP for your info if you want to do LAN networking). You can change the port with `-port X`. and it will start a server listening on `0.0.0.0:8050`. To view it, just go to http://localhost:8050 (the server prints out the local IP for your info if you want to do LAN networking). You can change the port with `-port X`, and you can listen *only* on localhost using `-host localhost`.
## Usage ## Usage

View File

@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func serve(port string) { func serve(host, port string) {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
router := gin.Default() router := gin.Default()
router.HTMLRender = loadTemplates("index.tmpl") router.HTMLRender = loadTemplates("index.tmpl")
@ -32,7 +32,7 @@ func serve(port string) {
router.DELETE("/oldlist", handleClearOldListItems) router.DELETE("/oldlist", handleClearOldListItems)
router.DELETE("/listitem", deleteListItem) router.DELETE("/listitem", deleteListItem)
router.Run(":" + port) router.Run(host + ":" + port)
} }
func loadTemplates(list ...string) multitemplate.Render { func loadTemplates(list ...string) multitemplate.Render {

13
main.go
View File

@ -23,8 +23,12 @@ func main() {
} }
pathToData = c.GlobalString("data") pathToData = c.GlobalString("data")
os.MkdirAll(pathToData, 0755) os.MkdirAll(pathToData, 0755)
fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, GetLocalIP(), c.GlobalString("port")) host := c.GlobalString("host")
serve(c.GlobalString("port")) if host == "" {
host = GetLocalIP()
}
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"))
return nil return nil
} }
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
@ -38,6 +42,11 @@ func main() {
Value: "", Value: "",
Usage: "data folder for migrating", Usage: "data folder for migrating",
}, },
cli.StringFlag{
Name: "host",
Value: "",
Usage: "host to use",
},
cli.StringFlag{ cli.StringFlag{
Name: "port,p", Name: "port,p",
Value: "8050", Value: "8050",