-
Notifications
You must be signed in to change notification settings - Fork 2
/
cell.go
42 lines (35 loc) · 845 Bytes
/
cell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package statedb
import (
"github.com/cilium/hive/cell"
)
// This module provides an in-memory database built on top of immutable radix trees
// As the database is based on an immutable data structure, the objects inserted into
// the database MUST NOT be mutated, but rather copied first!
var Cell = cell.Module(
"statedb",
"In-memory transactional database",
cell.Provide(
newHiveDB,
ScriptCommands,
),
)
type params struct {
cell.In
Lifecycle cell.Lifecycle
Metrics Metrics `optional:"true"`
}
func newHiveDB(p params) *DB {
db := New(WithMetrics(p.Metrics))
p.Lifecycle.Append(
cell.Hook{
OnStart: func(cell.HookContext) error {
return db.Start()
},
OnStop: func(cell.HookContext) error {
return db.Stop()
},
})
return db
}