Skip to content

Commit c989ef2

Browse files
committed
Remove redundant config struct
1 parent 4602d6d commit c989ef2

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

pkg/configs/db/memory/memory.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@ import (
66
"github.com/weaveworks/cortex/pkg/configs"
77
)
88

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-
219
// DB is an in-memory database for testing, and local development
2210
type DB struct {
23-
cfgs map[string]config
11+
cfgs map[string]configs.View
2412
id uint
2513
}
2614

2715
// New creates a new in-memory database
2816
func New(_, _ string) (*DB, error) {
2917
return &DB{
30-
cfgs: map[string]config{},
18+
cfgs: map[string]configs.View{},
3119
id: 0,
3220
}, nil
3321
}
@@ -38,31 +26,27 @@ func (d *DB) GetConfig(userID string) (configs.View, error) {
3826
if !ok {
3927
return configs.View{}, sql.ErrNoRows
4028
}
41-
return c.toView(), nil
29+
return c, nil
4230
}
4331

4432
// SetConfig sets configuration for a user.
4533
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)}
4735
d.id++
4836
return nil
4937
}
5038

5139
// GetAllConfigs gets all of the configs.
5240
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
5842
}
5943

6044
// GetConfigs gets all of the configs that have changed recently.
6145
func (d *DB) GetConfigs(since configs.ID) (map[string]configs.View, error) {
6246
cfgs := map[string]configs.View{}
6347
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
6650
}
6751
}
6852
return cfgs, nil

0 commit comments

Comments
 (0)