mirror of
https://github.com/crazy-max/diun.git
synced 2025-01-12 11:38:11 +00:00
1115234010
Add simple CLI to interact with Diun through gRPC Create image and notif proto services Compile and validate protos through a dedicated Dockerfile and bake target Implement proto definitions Move server as `serve` command New commands `image` and `notif` Refactor command line usage doc Better CLI error handling Tools build constraint to manage tools deps through go modules Add upgrade notes Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
36 lines
757 B
Go
36 lines
757 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)
|
|
return c.Update(func(tx *bolt.Tx) error {
|
|
b := tx.Bucket([]byte(bucketMetadata))
|
|
return b.Put([]byte(metadataKey), entryBytes)
|
|
})
|
|
}
|