-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathutil.go
49 lines (45 loc) · 1 KB
/
util.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
38
39
40
41
42
43
44
45
46
47
48
49
package revealgo
import (
"fmt"
"os/exec"
"runtime"
"strings"
"time"
)
func openBrowser(port int) {
<-time.After(100 * time.Millisecond)
url := fmt.Sprintf("http://localhost:%d/", port)
var args []string
var cmd string
switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
if err := exec.Command(cmd, args...).Start(); err != nil {
fmt.Printf("error when trying to open browser: %s", err.Error())
}
}
func addExtention(path string, ext string) string {
if strings.HasSuffix(path, fmt.Sprintf(".%s", ext)) {
return path
}
path = fmt.Sprintf("%s.%s", path, ext)
return path
}
func detectContentType(path string) string {
switch {
case strings.HasSuffix(path, ".css"):
return "text/css"
case strings.HasSuffix(path, ".js"):
return "application/javascript"
case strings.HasSuffix(path, ".svg"):
return "image/svg+xml"
}
return ""
}