-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (29 loc) · 844 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"net/http"
"flag"
"fmt"
"os/exec"
"runtime"
)
func main() {
var port = flag.Int("p", 8080, "Port to listen on")
var err error
fs := http.FileServer(http.Dir("."))
http.Handle("/", fs)
fmt.Println(fmt.Sprintf("Listening on port: %d...\n", *port))
http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
fmt.Sprintf("http://localhost:%d/", *port)
fmt.Println(runtime.GOOS)
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", fmt.Sprintf("http://localhost:%d/", *port)).Start()
case "windows", "darwin":
err = exec.Command("open", fmt.Sprintf("http://localhost:%d/", *port)).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
fmt.Print(err)
}
}