mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
add: 新增路由报告模块接口
This commit is contained in:
27
util/reporter/reporter.go
Normal file
27
util/reporter/reporter.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package reporter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/methods"
|
||||
)
|
||||
|
||||
type Reporter interface {
|
||||
Print()
|
||||
}
|
||||
|
||||
func New(rs map[uint16][]methods.TracerouteHop) Reporter {
|
||||
r := reporter{
|
||||
routeResult: rs,
|
||||
}
|
||||
fmt.Println(r)
|
||||
return &r
|
||||
}
|
||||
|
||||
type reporter struct {
|
||||
routeResult map[uint16][]methods.TracerouteHop
|
||||
}
|
||||
|
||||
func (r *reporter) Print() {
|
||||
fmt.Println(r)
|
||||
}
|
||||
24
util/reporter/reporter_test.go
Normal file
24
util/reporter/reporter_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package reporter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/methods"
|
||||
"github.com/xgadget-lab/nexttrace/methods/tcp"
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
)
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
ip := util.DomainLookUp("1.1.1.1")
|
||||
tcpTraceroute := tcp.New(ip, methods.TracerouteConfig{
|
||||
MaxHops: uint16(30),
|
||||
NumMeasurements: uint16(1),
|
||||
ParallelRequests: uint16(1),
|
||||
Port: 80,
|
||||
Timeout: time.Second / 2,
|
||||
})
|
||||
res, _ := tcpTraceroute.Start()
|
||||
r := New(*res)
|
||||
r.Print()
|
||||
}
|
||||
Reference in New Issue
Block a user