@@ -6,28 +6,16 @@ import (
6
6
"github.com/weaveworks/cortex/pkg/configs"
7
7
)
8
8
9
- type config struct {
10
- cfg configs.Config
11
- id configs.ID
12
- }
13
-
14
- func (c config ) toView () configs.View {
15
- return configs.View {
16
- ID : c .id ,
17
- Config : c .cfg ,
18
- }
19
- }
20
-
21
9
// DB is an in-memory database for testing, and local development
22
10
type DB struct {
23
- cfgs map [string ]config
11
+ cfgs map [string ]configs. View
24
12
id uint
25
13
}
26
14
27
15
// New creates a new in-memory database
28
16
func New (_ , _ string ) (* DB , error ) {
29
17
return & DB {
30
- cfgs : map [string ]config {},
18
+ cfgs : map [string ]configs. View {},
31
19
id : 0 ,
32
20
}, nil
33
21
}
@@ -38,31 +26,27 @@ func (d *DB) GetConfig(userID string) (configs.View, error) {
38
26
if ! ok {
39
27
return configs.View {}, sql .ErrNoRows
40
28
}
41
- return c . toView () , nil
29
+ return c , nil
42
30
}
43
31
44
32
// SetConfig sets configuration for a user.
45
33
func (d * DB ) SetConfig (userID string , cfg configs.Config ) error {
46
- d .cfgs [userID ] = config { cfg : cfg , id : configs .ID (d .id )}
34
+ d .cfgs [userID ] = configs. View { Config : cfg , ID : configs .ID (d .id )}
47
35
d .id ++
48
36
return nil
49
37
}
50
38
51
39
// GetAllConfigs gets all of the configs.
52
40
func (d * DB ) GetAllConfigs () (map [string ]configs.View , error ) {
53
- cfgs := map [string ]configs.View {}
54
- for user , c := range d .cfgs {
55
- cfgs [user ] = c .toView ()
56
- }
57
- return cfgs , nil
41
+ return d .cfgs , nil
58
42
}
59
43
60
44
// GetConfigs gets all of the configs that have changed recently.
61
45
func (d * DB ) GetConfigs (since configs.ID ) (map [string ]configs.View , error ) {
62
46
cfgs := map [string ]configs.View {}
63
47
for user , c := range d .cfgs {
64
- if c .id > since {
65
- cfgs [user ] = c . toView ()
48
+ if c .ID > since {
49
+ cfgs [user ] = c
66
50
}
67
51
}
68
52
return cfgs , nil
0 commit comments