@@ -78,6 +78,23 @@ type Reader struct {
7878 databaseType databaseType
7979}
8080
81+ // Option configures Reader behavior.
82+ type Option func (* readerOptions )
83+
84+ type readerOptions struct {
85+ maxminddb []maxminddb.ReaderOption
86+ }
87+
88+ func applyOptions (options []Option ) []maxminddb.ReaderOption {
89+ var opts readerOptions
90+ for _ , option := range options {
91+ if option != nil {
92+ option (& opts )
93+ }
94+ }
95+ return opts .maxminddb
96+ }
97+
8198// InvalidMethodError is returned when a lookup method is called on a
8299// database that it does not support. For instance, calling the ISP method
83100// on a City database.
@@ -104,10 +121,9 @@ func (e UnknownDatabaseTypeError) Error() string {
104121
105122// Open takes a string path to a file and returns a Reader struct or an error.
106123// 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. 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 ... )
124+ // Reader object to return the resources to the system.
125+ func Open (file string , options ... Option ) (* Reader , error ) {
126+ reader , err := maxminddb .Open (file , applyOptions (options )... )
111127 if err != nil {
112128 return nil , err
113129 }
@@ -118,10 +134,9 @@ func Open(file string, options ...maxminddb.ReaderOption) (*Reader, error) {
118134// OpenBytes takes a byte slice corresponding to a GeoIP2/GeoLite2 database
119135// file and returns a Reader struct or an error. Note that the byte slice is
120136// used directly; any modification of it after opening the database will result
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 ... )
137+ // in errors while reading from the database.
138+ func OpenBytes (bytes []byte , options ... Option ) (* Reader , error ) {
139+ reader , err := maxminddb .OpenBytes (bytes , applyOptions (options )... )
125140 if err != nil {
126141 return nil , err
127142 }
@@ -136,7 +151,7 @@ func OpenBytes(bytes []byte, options ...maxminddb.ReaderOption) (*Reader, error)
136151//
137152// Deprecated: Use OpenBytes instead. FromBytes will be removed in a future
138153// version.
139- func FromBytes (bytes []byte , options ... maxminddb. ReaderOption ) (* Reader , error ) {
154+ func FromBytes (bytes []byte , options ... Option ) (* Reader , error ) {
140155 return OpenBytes (bytes , options ... )
141156}
142157
0 commit comments