@@ -112,6 +112,7 @@ import (
112
112
"net/netip"
113
113
"os"
114
114
"runtime"
115
+ "time"
115
116
116
117
"github.com/oschwald/maxminddb-golang/v2/internal/decoder"
117
118
"github.com/oschwald/maxminddb-golang/v2/internal/mmdberrors"
@@ -137,20 +138,62 @@ type Reader struct {
137
138
hasMappedFile bool
138
139
}
139
140
140
- // Metadata holds the metadata decoded from the MaxMind DB file. In particular
141
- // it has the format version, the build time as Unix epoch time, the database
142
- // type and description, the IP version supported, and a slice of the natural
143
- // languages included.
141
+ // Metadata holds the metadata decoded from the MaxMind DB file.
142
+ //
143
+ // Key fields include:
144
+ // - DatabaseType: indicates the structure of data records (e.g., "GeoIP2-City")
145
+ // - Description: localized descriptions in various languages
146
+ // - Languages: locale codes for which the database may contain localized data
147
+ // - BuildEpoch: database build timestamp as Unix epoch seconds
148
+ // - IPVersion: supported IP version (4 for IPv4-only, 6 for IPv4/IPv6)
149
+ // - NodeCount: number of nodes in the search tree
150
+ // - RecordSize: size in bits of each record in the search tree (24, 28, or 32)
151
+ //
152
+ // For detailed field descriptions, see the MaxMind DB specification:
153
+ // https://maxmind.github.io/MaxMind-DB/
144
154
type Metadata struct {
145
- Description map [string ]string `maxminddb:"description"`
146
- DatabaseType string `maxminddb:"database_type"`
147
- Languages []string `maxminddb:"languages"`
148
- BinaryFormatMajorVersion uint `maxminddb:"binary_format_major_version"`
149
- BinaryFormatMinorVersion uint `maxminddb:"binary_format_minor_version"`
150
- BuildEpoch uint `maxminddb:"build_epoch"`
151
- IPVersion uint `maxminddb:"ip_version"`
152
- NodeCount uint `maxminddb:"node_count"`
153
- RecordSize uint `maxminddb:"record_size"`
155
+ // Description contains localized database descriptions.
156
+ // Keys are language codes (e.g., "en", "zh-CN"), values are UTF-8 descriptions.
157
+ Description map [string ]string `maxminddb:"description"`
158
+
159
+ // DatabaseType indicates the structure of data records associated with IP addresses.
160
+ // Names starting with "GeoIP" are reserved for MaxMind databases.
161
+ DatabaseType string `maxminddb:"database_type"`
162
+
163
+ // Languages lists locale codes for which this database may contain localized data.
164
+ // Records should not contain localized data for locales not in this array.
165
+ Languages []string `maxminddb:"languages"`
166
+
167
+ // BinaryFormatMajorVersion is the major version of the MaxMind DB binary format.
168
+ // Current supported version is 2.
169
+ BinaryFormatMajorVersion uint `maxminddb:"binary_format_major_version"`
170
+
171
+ // BinaryFormatMinorVersion is the minor version of the MaxMind DB binary format.
172
+ // Current supported version is 0.
173
+ BinaryFormatMinorVersion uint `maxminddb:"binary_format_minor_version"`
174
+
175
+ // BuildEpoch contains the database build timestamp as Unix epoch seconds.
176
+ // Use BuildTime() method for a time.Time representation.
177
+ BuildEpoch uint `maxminddb:"build_epoch"`
178
+
179
+ // IPVersion indicates the IP version support:
180
+ // 4: IPv4 addresses only
181
+ // 6: Both IPv4 and IPv6 addresses
182
+ IPVersion uint `maxminddb:"ip_version"`
183
+
184
+ // NodeCount is the number of nodes in the search tree.
185
+ NodeCount uint `maxminddb:"node_count"`
186
+
187
+ // RecordSize is the size in bits of each record in the search tree.
188
+ // Valid values are 24, 28, or 32.
189
+ RecordSize uint `maxminddb:"record_size"`
190
+ }
191
+
192
+ // BuildTime returns the database build time as a time.Time.
193
+ // This is a convenience method that converts the BuildEpoch field
194
+ // from Unix epoch seconds to a time.Time value.
195
+ func (m Metadata ) BuildTime () time.Time {
196
+ return time .Unix (int64 (m .BuildEpoch ), 0 )
154
197
}
155
198
156
199
type readerOptions struct {}
0 commit comments