-
Notifications
You must be signed in to change notification settings - Fork 110
/
module.go
47 lines (38 loc) · 1.4 KB
/
module.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
// Package main is a module, which serves all four custom model types in the customresources examples, including both custom APIs.
package main
import (
"context"
"github.com/edaniels/golog"
"go.viam.com/rdk/components/base"
"go.viam.com/rdk/module"
"go.viam.com/rdk/services/navigation"
"go.viam.com/rdk/examples/customresources/apis/gizmoapi"
"go.viam.com/rdk/examples/customresources/apis/summationapi"
"go.viam.com/rdk/examples/customresources/models/mybase"
"go.viam.com/rdk/examples/customresources/models/mygizmo"
"go.viam.com/rdk/examples/customresources/models/mynavigation"
"go.viam.com/rdk/examples/customresources/models/mysum"
"go.viam.com/utils"
)
func main() {
utils.ContextualMain(mainWithArgs, golog.NewDevelopmentLogger("ComplexModule"))
}
func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) (err error) {
myMod, err := module.NewModuleFromArgs(ctx, logger)
if err != nil {
return err
}
// Models and APIs add helpers to the registry during their init().
// They can then be added to the module here.
myMod.AddModelFromRegistry(ctx, gizmoapi.API, mygizmo.Model)
myMod.AddModelFromRegistry(ctx, summationapi.API, mysum.Model)
myMod.AddModelFromRegistry(ctx, base.API, mybase.Model)
myMod.AddModelFromRegistry(ctx, navigation.API, mynavigation.Model)
err = myMod.Start(ctx)
defer myMod.Close(ctx)
if err != nil {
return err
}
<-ctx.Done()
return nil
}