diff --git a/bgptools/pop.go b/bgptools/pop.go index 0c9c123..661d449 100644 --- a/bgptools/pop.go +++ b/bgptools/pop.go @@ -8,8 +8,8 @@ import ( "regexp" "strings" - "github.com/imroc/req/v3" "github.com/google/uuid" + "github.com/imroc/req/v3" ) type ASCard struct { @@ -36,6 +36,7 @@ type Upstream struct { type PoPResult struct { TargetASN string Upstreams []Upstream + Result string } var tier1Global = map[string]string{ @@ -228,8 +229,14 @@ func GetPoPInfo(ip string) (*PoPResult, error) { return nil, fmt.Errorf("无法识别目标 ASN") } upstreams := findUpstreams(targetASN, nodes, edges) + var result string + for _, u := range upstreams { + abbr := getISPAbbr(u.ASN, u.Name) + result += fmt.Sprintf("AS%s - %s [%s]\n", u.ASN, abbr, u.Type) + } return &PoPResult{ TargetASN: targetASN, Upstreams: upstreams, + Result: result, }, nil } diff --git a/bgptools/pop_test.go b/bgptools/pop_test.go index 297d48d..b273daa 100644 --- a/bgptools/pop_test.go +++ b/bgptools/pop_test.go @@ -13,8 +13,5 @@ func TestGetPoPInfo(t *testing.T) { } fmt.Printf("目标 ASN: %s\n", result.TargetASN) fmt.Println("上游信息:") - for _, u := range result.Upstreams { - abbr := getISPAbbr(u.ASN, u.Name) - fmt.Printf("AS%s - %s [%s]\n", u.ASN, abbr, u.Type) - } + fmt.Print(result.Result) }