diff --git a/pkg/util/locode/db/boltdb/calls.go b/pkg/util/locode/db/boltdb/calls.go index 2c10aa0de..f260da8cd 100644 --- a/pkg/util/locode/db/boltdb/calls.go +++ b/pkg/util/locode/db/boltdb/calls.go @@ -13,6 +13,8 @@ import ( // Open opens underlying BoltDB instance. // // Timeout of BoltDB opening is 3s (only for Linux or Darwin). +// +// Opens BoltDB in read-only mode if DB is read-only. func (db *DB) Open() error { // copy-paste from metabase: // consider universal Open/Close for BoltDB wrappers @@ -98,6 +100,7 @@ func recordFromValue(data []byte) (*locodedb.Record, error) { // The records are stored in internal binary JSON format. // // Must not be called before successful Open call. +// Must not be called in read-only mode: behavior is undefined. func (db *DB) Put(key locodedb.Key, rec locodedb.Record) error { return db.bolt.Update(func(tx *bbolt.Tx) error { countryKey, err := countryBucketKey(key.CountryCode()) diff --git a/pkg/util/locode/db/boltdb/opts.go b/pkg/util/locode/db/boltdb/opts.go index 072655011..62b132596 100644 --- a/pkg/util/locode/db/boltdb/opts.go +++ b/pkg/util/locode/db/boltdb/opts.go @@ -24,3 +24,13 @@ func defaultOpts() *options { }, } } + +// ReadOnly enables read-only mode of the DB. +// +// Do not call DB.Put method on instances with +// this option: the behavior is undefined. +func ReadOnly() Option { + return func(o *options) { + o.boltOpts.ReadOnly = true + } +}