-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbiu.go
More file actions
71 lines (62 loc) · 1.7 KB
/
biu.go
File metadata and controls
71 lines (62 loc) · 1.7 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"net/http"
"log"
"flag"
"strconv"
"os"
"github.com/fatih/color"
"github.com/thewinds/biu/setting"
)
var (
// NumOfWatcherFiles 观察的文件个数
NumOfWatcherFiles = 0
// RefreshTimes 刷新的次数
RefreshTimes = 0
)
func main() {
color.White(setting.Logo)
initFlag()
startServ()
StartWatch()
}
func startServ() {
wshander := InitNotifyServ()
// 通知页面刷新的websocket服务
http.Handle(setting.WSServPath, wshander)
// 文件服务器
http.Handle("/", InjectFileServer(http.Dir(""), InjectScriptFunc))
// 获取要注入的js代码的handler
http.HandleFunc(setting.InjectScriptPath, InjectScriptHandler)
color.Green("[Biu] 启动http服务 localhost:" + setting.Port)
go func() {
err := http.ListenAndServe(":"+setting.Port, nil)
if err != nil {
color.Red("启动http服务器失败")
os.Exit(1)
}
}()
}
func initFlag() {
port := flag.String("p", "8080", "指定运行的端口")
help := flag.Bool("help", false, "查看帮助")
flag.Parse()
if *help == true {
color.Red("\nbiu 实时刷新工具 ❤\n")
fmt.Printf("\n使用帮助\n")
fmt.Println("biu \t\t运行http服务器在默认端口8080并实时刷新")
fmt.Println("biu -p=端口号\t运行http服务器在指定端口并实时刷新")
fmt.Println("biu -help\t查看帮助")
fmt.Println()
color.Cyan("Powered by thewinds")
os.Exit(0)
}
if _, err := strconv.Atoi(*port); err != nil {
log.Fatal("端口不正确,请检查")
}
setting.Port = *port
}
func updateTerm() {
color.Cyan("\033[100D[ %d个文件正在被监控 Biu为您持续刷新%d次 ]\033[1A", NumOfWatcherFiles, RefreshTimes)
}