Skip to content

Commit 79dbfb9

Browse files
committed
Forward reader options to maxminddb
Allow geoip2.Open and OpenBytes to accept variadic reader options and pass them through to the underlying maxminddb helpers. Extend the deprecated FromBytes helper to support the same options and document the change in the changelog.
1 parent ca25f8f commit 79dbfb9

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 2.0.0 -
22

33
- Updated dependency on `github.com/oschwald/maxminddb-golang/v2` to `v2.0.0`.
4+
- Allow `Open` and `OpenBytes` to forward reader options to `maxminddb-golang`,
5+
enabling advanced reader configuration.
46

57
# 2.0.0-beta.4 - 2025-08-23
68

reader.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ func (e UnknownDatabaseTypeError) Error() string {
104104

105105
// Open takes a string path to a file and returns a Reader struct or an error.
106106
// The database file is opened using a memory map. Use the Close method on the
107-
// Reader object to return the resources to the system.
108-
func Open(file string) (*Reader, error) {
109-
reader, err := maxminddb.Open(file)
107+
// Reader object to return the resources to the system. Any reader options
108+
// provided are passed directly to maxminddb.Open.
109+
func Open(file string, options ...maxminddb.ReaderOption) (*Reader, error) {
110+
reader, err := maxminddb.Open(file, options...)
110111
if err != nil {
111112
return nil, err
112113
}
@@ -117,9 +118,10 @@ func Open(file string) (*Reader, error) {
117118
// OpenBytes takes a byte slice corresponding to a GeoIP2/GeoLite2 database
118119
// file and returns a Reader struct or an error. Note that the byte slice is
119120
// used directly; any modification of it after opening the database will result
120-
// in errors while reading from the database.
121-
func OpenBytes(bytes []byte) (*Reader, error) {
122-
reader, err := maxminddb.OpenBytes(bytes)
121+
// in errors while reading from the database. Any reader options provided are
122+
// passed directly to maxminddb.OpenBytes.
123+
func OpenBytes(bytes []byte, options ...maxminddb.ReaderOption) (*Reader, error) {
124+
reader, err := maxminddb.OpenBytes(bytes, options...)
123125
if err != nil {
124126
return nil, err
125127
}
@@ -134,8 +136,8 @@ func OpenBytes(bytes []byte) (*Reader, error) {
134136
//
135137
// Deprecated: Use OpenBytes instead. FromBytes will be removed in a future
136138
// version.
137-
func FromBytes(bytes []byte) (*Reader, error) {
138-
return OpenBytes(bytes)
139+
func FromBytes(bytes []byte, options ...maxminddb.ReaderOption) (*Reader, error) {
140+
return OpenBytes(bytes, options...)
139141
}
140142

141143
func getDBType(reader *maxminddb.Reader) (databaseType, error) {

0 commit comments

Comments
 (0)