@@ -50,13 +50,21 @@ type Metadata struct {
5050 RecordSize uint `maxminddb:"record_size"`
5151}
5252
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+ // ReadersOption are options for [Open] and [FromBytes].
56+ //
57+ // This was added to allow for future options, e.g., for caching, without
58+ // causing a breaking API change.
59+ type ReaderOption func (* readerOptions )
60+
61+ // Open takes a string path to a MaxMind DB file and any options. It returns a
62+ // Reader structure or an error. The database file is opened using a memory
63+ // map on supported platforms. On platforms without memory map support, such
5664// as WebAssembly or Google App Engine, or if the memory map attempt fails
5765// due to lack of support from the filesystem, the database is loaded into memory.
5866// Use the Close method on the Reader object to return the resources to the system.
59- func Open (file string ) (* Reader , error ) {
67+ func Open (file string , options ... ReaderOption ) (* Reader , error ) {
6068 mapFile , err := os .Open (file )
6169 if err != nil {
6270 return nil , err
@@ -88,12 +96,12 @@ func Open(file string) (*Reader, error) {
8896 if err != nil {
8997 return nil , err
9098 }
91- return FromBytes (data )
99+ return FromBytes (data , options ... )
92100 }
93101 return nil , err
94102 }
95103
96- reader , err := FromBytes (data )
104+ reader , err := FromBytes (data , options ... )
97105 if err != nil {
98106 _ = munmap (data )
99107 return nil , err
@@ -122,9 +130,14 @@ func (r *Reader) Close() error {
122130 return err
123131}
124132
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 ) {
133+ // FromBytes takes a byte slice corresponding to a MaxMind DB file and any
134+ // options. It returns a Reader structure or an error.
135+ func FromBytes (buffer []byte , options ... ReaderOption ) (* Reader , error ) {
136+ opts := & readerOptions {}
137+ for _ , option := range options {
138+ option (opts )
139+ }
140+
128141 metadataStart := bytes .LastIndex (buffer , metadataStartMarker )
129142
130143 if metadataStart == - 1 {
0 commit comments