-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathsources.go
55 lines (46 loc) · 1.66 KB
/
sources.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
package memdb
import (
"context"
"fmt"
"github.com/influxdata/influxdb/v2/chronograf"
)
// Ensure SourcesStore implements chronograf.SourcesStore.
var _ chronograf.SourcesStore = &SourcesStore{}
// SourcesStore implements the chronograf.SourcesStore interface
type SourcesStore struct {
Source *chronograf.Source
}
// Add does not have any effect
func (store *SourcesStore) Add(ctx context.Context, src chronograf.Source) (chronograf.Source, error) {
return chronograf.Source{}, fmt.Errorf("in-memory SourcesStore does not support adding a Source")
}
// All will return a slice containing a configured source
func (store *SourcesStore) All(ctx context.Context) ([]chronograf.Source, error) {
if store.Source != nil {
return []chronograf.Source{*store.Source}, nil
}
return nil, nil
}
// Delete removes the SourcesStore.Soruce if it matches the provided Source
func (store *SourcesStore) Delete(ctx context.Context, src chronograf.Source) error {
if store.Source == nil || store.Source.ID != src.ID {
return fmt.Errorf("unable to find Source with id %d", src.ID)
}
store.Source = nil
return nil
}
// Get returns the configured source if the id matches
func (store *SourcesStore) Get(ctx context.Context, id int) (chronograf.Source, error) {
if store.Source == nil || store.Source.ID != id {
return chronograf.Source{}, fmt.Errorf("unable to find Source with id %d", id)
}
return *store.Source, nil
}
// Update does nothing
func (store *SourcesStore) Update(ctx context.Context, src chronograf.Source) error {
if store.Source == nil || store.Source.ID != src.ID {
return fmt.Errorf("unable to find Source with id %d", src.ID)
}
store.Source = &src
return nil
}