@@ -50,13 +50,17 @@ type Metadata struct {
50
50
RecordSize uint `maxminddb:"record_size"`
51
51
}
52
52
53
- // Open takes a string path to a MaxMind DB file and returns a Reader
54
- // structure or an error. The database file is opened using a memory map
55
- // on supported platforms. On platforms without memory map support, such
53
+ type readerOptions struct {}
54
+
55
+ type ReaderOption func (* readerOptions )
56
+
57
+ // Open takes a string path to a MaxMind DB file and any options. It returns a
58
+ // Reader structure or an error. The database file is opened using a memory
59
+ // map on supported platforms. On platforms without memory map support, such
56
60
// as WebAssembly or Google App Engine, or if the memory map attempt fails
57
61
// due to lack of support from the filesystem, the database is loaded into memory.
58
62
// Use the Close method on the Reader object to return the resources to the system.
59
- func Open (file string ) (* Reader , error ) {
63
+ func Open (file string , options ... ReaderOption ) (* Reader , error ) {
60
64
mapFile , err := os .Open (file )
61
65
if err != nil {
62
66
return nil , err
@@ -88,12 +92,12 @@ func Open(file string) (*Reader, error) {
88
92
if err != nil {
89
93
return nil , err
90
94
}
91
- return FromBytes (data )
95
+ return FromBytes (data , options ... )
92
96
}
93
97
return nil , err
94
98
}
95
99
96
- reader , err := FromBytes (data )
100
+ reader , err := FromBytes (data , options ... )
97
101
if err != nil {
98
102
_ = munmap (data )
99
103
return nil , err
@@ -122,9 +126,14 @@ func (r *Reader) Close() error {
122
126
return err
123
127
}
124
128
125
- // FromBytes takes a byte slice corresponding to a MaxMind DB file and returns
126
- // a Reader structure or an error.
127
- func FromBytes (buffer []byte ) (* Reader , error ) {
129
+ // FromBytes takes a byte slice corresponding to a MaxMind DB file and any
130
+ // options. It returns a Reader structure or an error.
131
+ func FromBytes (buffer []byte , options ... ReaderOption ) (* Reader , error ) {
132
+ opts := & readerOptions {}
133
+ for _ , option := range options {
134
+ option (opts )
135
+ }
136
+
128
137
metadataStart := bytes .LastIndex (buffer , metadataStartMarker )
129
138
130
139
if metadataStart == - 1 {
0 commit comments