-
Notifications
You must be signed in to change notification settings - Fork 110
/
generic.go
41 lines (35 loc) · 1.07 KB
/
generic.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
// Package fake implements a fake generic service.
package fake
import (
"context"
"go.viam.com/rdk/logging"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/services/generic"
)
func init() {
resource.RegisterService(
generic.API,
resource.DefaultModelFamily.WithModel("fake"),
resource.Registration[resource.Resource, resource.NoNativeConfig]{Constructor: func(
ctx context.Context,
deps resource.Dependencies,
conf resource.Config,
logger logging.Logger,
) (resource.Resource, error) {
return newGeneric(conf.ResourceName(), logger), nil
}})
}
func newGeneric(name resource.Name, logger logging.Logger) resource.Resource {
return &Generic{Named: name.AsNamed(), logger: logger}
}
// Generic is a fake Generic service that always echos input back to the caller.
type Generic struct {
resource.Named
resource.TriviallyReconfigurable
resource.TriviallyCloseable
logger logging.Logger
}
// DoCommand echos input back to the caller.
func (fg *Generic) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
return cmd, nil
}