fix: 修复文本生成

This commit is contained in:
spiritlhl 2025-08-01 13:41:56 +00:00
parent 4d5b3fd5cb
commit a36c3eff82
2 changed files with 9 additions and 5 deletions

View File

@ -8,8 +8,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/imroc/req/v3"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/imroc/req/v3"
) )
type ASCard struct { type ASCard struct {
@ -36,6 +36,7 @@ type Upstream struct {
type PoPResult struct { type PoPResult struct {
TargetASN string TargetASN string
Upstreams []Upstream Upstreams []Upstream
Result string
} }
var tier1Global = map[string]string{ var tier1Global = map[string]string{
@ -228,8 +229,14 @@ func GetPoPInfo(ip string) (*PoPResult, error) {
return nil, fmt.Errorf("无法识别目标 ASN") return nil, fmt.Errorf("无法识别目标 ASN")
} }
upstreams := findUpstreams(targetASN, nodes, edges) 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{ return &PoPResult{
TargetASN: targetASN, TargetASN: targetASN,
Upstreams: upstreams, Upstreams: upstreams,
Result: result,
}, nil }, nil
} }

View File

@ -13,8 +13,5 @@ func TestGetPoPInfo(t *testing.T) {
} }
fmt.Printf("目标 ASN: %s\n", result.TargetASN) fmt.Printf("目标 ASN: %s\n", result.TargetASN)
fmt.Println("上游信息:") fmt.Println("上游信息:")
for _, u := range result.Upstreams { fmt.Print(result.Result)
abbr := getISPAbbr(u.ASN, u.Name)
fmt.Printf("AS%s - %s [%s]\n", u.ASN, abbr, u.Type)
}
} }