Skip to content

Commit

Permalink
Implement close for GeoIP databases
Browse files Browse the repository at this point in the history
  • Loading branch information
H1JK committed Feb 23, 2024
1 parent a99a813 commit d761558
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/geo/cmd_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func check(cmd *cobra.Command, args []string) error {
fmt.Println("❌Failed to verify GeoIP database!")
fmt.Println("Error:", err)
}
mmdb.Close()
if mmdb.Metadata.Description["PLACEHOLDER"] == "geo" {
mmdb.Metadata.Description = nil
}
Expand Down
1 change: 1 addition & 0 deletions cmd/geo/cmd_look.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func look(cmd *cobra.Command, args []string) error {
}

codes := db.LookupCode(ip)
db.Close()
for _, code := range codes {
result[strings.ToUpper(code)] = struct{}{}
}
Expand Down
4 changes: 4 additions & 0 deletions geoip/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ func (db Database) LookupCode(ip net.IP) []string {
panic(F.ToString("unknown GeoIP database type: ", string(db.MemoryType)))
}
}

func (db Database) Close() error {
return db.reader.Close()
}

0 comments on commit d761558

Please sign in to comment.