-
Notifications
You must be signed in to change notification settings - Fork 2
/
gopcap.go
49 lines (42 loc) · 956 Bytes
/
gopcap.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 gopcap
import (
"log"
"os"
"github.com/Lqlsoftware/gopcap/http"
"github.com/Lqlsoftware/gopcap/php"
"github.com/google/gopacket/layers"
)
// 启动服务器
func Start(port layers.TCPPort) {
log.SetPrefix("[Gopcap] ")
// server根目录root文件夹
mkRoot()
// 选择适配器
adapter := getAdapter()
// 开启TCP端口监听
listen(adapter, port)
}
// 绑定URL
func Bind(Url string, method http.HttpMethod, handler func(*http.HttpRequest,*http.HttpResponse)) {
err := http.AddRouter([]byte(Url), method, handler)
check(err)
}
// 解绑URL
func DeBind(Url string, method http.HttpMethod) {
err := http.RemoveRouter([]byte(Url), method)
check(err)
}
func SetUsePhp() {
php.UsePhp = true
}
// 创建根目录root文件夹
func mkRoot() {
if !checkDirIsExist("root") {
err := os.Mkdir("root", os.ModePerm)
check(err)
}
if !checkDirIsExist("root/_temp") {
err := os.Mkdir("root/_temp", os.ModePerm)
check(err)
}
}