From 4ce4d85a3e871c29c91f1773de724f1a1ab7a4f1 Mon Sep 17 00:00:00 2001 From: naiba Date: Sun, 28 Jul 2024 15:11:50 +0800 Subject: [PATCH] improve: Handle case when host is not found in LookupGeoIP --- service/rpc/nezha.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index 16bc6855..4c8b916c 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -243,9 +243,10 @@ func (s *NezhaHandler) LookupGeoIP(c context.Context, r *pb.GeoIP) (*pb.GeoIP, e // 将地区码写入到 Host singleton.ServerLock.RLock() defer singleton.ServerLock.RUnlock() - if singleton.ServerList[clientID].Host != nil { - singleton.ServerList[clientID].Host.CountryCode = location + if singleton.ServerList[clientID].Host == nil { + return nil, fmt.Errorf("host not found") } + singleton.ServerList[clientID].Host.CountryCode = location return &pb.GeoIP{Ip: ip, CountryCode: location}, nil }