Skip to content

Commit 747a2ed

Browse files
committed
Add -o switch to open browser
1 parent 7820987 commit 747a2ed

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"github.com/labstack/echo"
77
"github.com/labstack/echo/middleware"
8+
"github.com/skratchdot/open-golang/open"
89
"os"
910
)
1011

@@ -17,7 +18,7 @@ func createAuth(cred []string) echo.MiddlewareFunc {
1718
})
1819
}
1920

20-
func server(port string, cred []string, debug bool) {
21+
func server(port string, cred []string, debug bool, browser bool) {
2122
e := echo.New()
2223

2324
if debug {
@@ -37,6 +38,9 @@ func server(port string, cred []string, debug bool) {
3738
e.Static("/plugins", "plugins")
3839
e.Static("/", "public")
3940

41+
if browser {
42+
open.Run("http://localhost:" + port + "/")
43+
}
4044
e.Start(":" + port)
4145
}
4246

@@ -49,6 +53,7 @@ func main() {
4953
portPtr := flag.Int("p", 8080, "server port")
5054
credPtr := flag.String("c", "admin:123456", "admin username & password")
5155
debugPtr := flag.Bool("d", false, "disable or enable logging")
56+
browserPtr := flag.Bool("o", false, "open browser")
5257
flag.Parse()
5358

5459
port := fmt.Sprintf("%d", *portPtr)
@@ -60,5 +65,5 @@ func main() {
6065
os.Exit(1)
6166
}
6267

63-
server(port, credArr, *debugPtr)
68+
server(port, credArr, *debugPtr, *browserPtr)
6469
}

0 commit comments

Comments
 (0)