-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
58 lines (52 loc) · 1.54 KB
/
handler.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
50
51
52
53
54
55
56
57
58
package main
import (
"log"
"net/http"
"os/exec"
"runtime"
)
//NewRouter creates the router
func startLocalServer() {
staticViewHandle := http.StripPrefix("/hehe/view/", http.FileServer(http.Dir("./assets/static/")))
http.Handle("/hehe/view/", staticViewHandle)
http.HandleFunc("/hehe/api/pay", payPage)
http.HandleFunc("/hehe/api/videoPage", videoPage)
log.Fatal(http.ListenAndServe(":"+config.Server.Port, nil))
}
//to pay page
func payPage(w http.ResponseWriter, r *http.Request) {
log.Println("in pay page")
err := open(reloadViewRoot + config.Assets.Page.Pay)
if err != nil {
log.Println("Open url error, the message is ", err)
}
}
func videoPage(w http.ResponseWriter, r *http.Request) {
err := open(reloadViewRoot + config.Assets.Page.Video)
if err != nil {
log.Println("Open url error, the message is ", err)
}
}
func posterPage(w http.ResponseWriter, r *http.Request) {
log.Println("in method poster begin")
open("")
log.Println("in method poster end")
}
func open(uri string) error {
var chromePath string
switch runtime.GOOS {
case "windows":
chromePath = config.Assets.Chrome.Windows
case "darwin":
chromePath = config.Assets.Chrome.Mac
case "linux":
chromePath = config.Assets.Chrome.Linux
default:
}
if chromePath == "" {
log.Fatal("get chrome path faild,check config or chrome exits or not")
}
log.Println(chromePath, uri, DISABLE_TRANSLATE, TEST_TYPE, DISABLE_WEB_SECURITY, FULL_SCREEN_PARAM)
cmd := exec.Command(chromePath, uri, DISABLE_TRANSLATE, TEST_TYPE, FULL_SCREEN_PARAM)
return cmd.Start()
}