Skip to content

Commit b839abe

Browse files
authored
Merge pull request #6 from bubble-diff/dev
优化代码
2 parents e7686b4 + c54d848 commit b839abe

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

const.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package main
22

33
// 参数常量
44
const (
5-
SnapshotLen int32 = 65536 * 4
6-
SettingsFilePath = "./settings.json"
5+
SnapshotLen int32 = 65536 * 4
6+
SettingsFilePath = "./settings.json"
77
)
88

99
// 应用层协议类型
@@ -14,4 +14,4 @@ const (
1414

1515
const (
1616
ApiAddRecord = "/record/add"
17-
)
17+
)

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var debugmode bool
1818

19-
func init() {
19+
func Init() {
2020
flag.BoolVar(&debugmode, "debug", false, "Run as debug mode, read settings file to override task configuration if existsed.")
2121
flag.Parse()
2222

@@ -37,12 +37,14 @@ func init() {
3737
}
3838

3939
func main() {
40+
Init()
41+
4042
handle, err := pcap.OpenLive(configuration.Device, SnapshotLen, false, pcap.BlockForever)
41-
defer handle.Close()
4243
if err != nil {
4344
logrus.Error(err)
4445
logrus.Fatal("Try sudo.")
4546
}
47+
defer handle.Close()
4648

4749
// 过滤出当前服务的流量
4850
filter := fmt.Sprintf(

0 commit comments

Comments
 (0)