mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-30 17:47:20 +01:00
* Leave default image platform empty for static provider (see FAQ doc) * Handle platform variant * Add database migration process * Switch to Open Container Specification labels as label-schema.org ones are deprecated * Remove unneeded `diun.os` and `diun.arch` docker labels Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
40 lines
771 B
Go
40 lines
771 B
Go
package db
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
bolt "go.etcd.io/bbolt"
|
|
)
|
|
|
|
// Metadata represents db metadata informations
|
|
type Metadata struct {
|
|
Version int
|
|
}
|
|
|
|
const (
|
|
metadataKey = "ID"
|
|
)
|
|
|
|
// ReadMetadata returns db metadata
|
|
func (c *Client) ReadMetadata() error {
|
|
return c.View(func(tx *bolt.Tx) error {
|
|
b := tx.Bucket([]byte(bucketMetadata))
|
|
if entryBytes := b.Get([]byte(metadataKey)); entryBytes != nil {
|
|
return json.Unmarshal(entryBytes, &c.metadata)
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// WriteMetadata writes db metadata
|
|
func (c *Client) WriteMetadata(metadata Metadata) error {
|
|
entryBytes, _ := json.Marshal(metadata)
|
|
|
|
err := c.Update(func(tx *bolt.Tx) error {
|
|
b := tx.Bucket([]byte(bucketMetadata))
|
|
return b.Put([]byte(metadataKey), entryBytes)
|
|
})
|
|
|
|
return err
|
|
}
|