-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubase.go
67 lines (58 loc) · 1.63 KB
/
ubase.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ubase
import (
"github.com/uplus-io/ucluster/v1"
"github.com/uplus-io/uengine"
)
type UBaseConfig struct {
Cluster v1.UClusterConfig `json:"cluster" yaml:"cluster"`
StorageConfig StorageConfig `json:"storage" yaml:"storage"`
LogConfig LogConfig `json:"log" yaml:"log"`
}
type StorageConfig struct {
Engine string `json:"engine" yaml:"engine"`
Meta string `json:"meta" yaml:"meta"`
Wal string `json:"wal" yaml:"wal"`
Partitions []string `json:"partitions" yaml:"partitions"`
}
type LogConfig struct {
Path string `json:"path" yaml:"path"`
Filename string `json:"filename" yaml:"filename"`
Level uint32 `json:"level" yaml:"level"`
}
type UBase struct {
config *UBaseConfig
cluster *v1.UCluster
engine *uengine.Engine
}
func NewBase(config *UBaseConfig) *UBase {
engine := startEngine(config)
base := &UBase{
config: config,
engine: engine,
cluster: v1.NewUCluster(&config.Cluster),
}
configure(config, base)
return base
}
func configure(config *UBaseConfig, base *UBase) {
config.Cluster.Delegate = NewBaseDelegate(base)
config.Cluster.MessageDelegate = NewBaseMessageDelegate(base)
config.Cluster.DataDelegate = NewBaseDataDelegate(base)
}
func startEngine(config *UBaseConfig) *uengine.Engine {
storageConfig := config.StorageConfig
engineConfig := uengine.UEngineConfig{
Engine: storageConfig.Engine,
Wal: storageConfig.Wal,
Meta: storageConfig.Meta,
Partitions: storageConfig.Partitions,
}
engine := uengine.NewEngine(engineConfig)
return engine
}
func (p *UBase) Serving() {
err := p.cluster.Serving()
if err != nil {
panic(err)
}
}