-
Notifications
You must be signed in to change notification settings - Fork 110
/
module.go
60 lines (53 loc) · 1.7 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
48
49
50
51
52
53
54
55
56
57
58
59
60
// Package main is a module, which serves all four custom model types in the customresources examples, including both custom APIs.
package main
import (
"context"
"go.viam.com/utils"
"go.viam.com/rdk/components/base"
"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/rdk/logging"
"go.viam.com/rdk/module"
"go.viam.com/rdk/services/navigation"
)
func main() {
// NewLoggerFromArgs will create a logging.Logger at "DebugLevel" if
// "--log-level=debug" is the third argument in os.Args and at "InfoLevel"
// otherwise.
utils.ContextualMain(mainWithArgs, module.NewLoggerFromArgs("complexmodule"))
}
func mainWithArgs(ctx context.Context, args []string, logger logging.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.
err = myMod.AddModelFromRegistry(ctx, gizmoapi.API, mygizmo.Model)
if err != nil {
return err
}
err = myMod.AddModelFromRegistry(ctx, summationapi.API, mysum.Model)
if err != nil {
return err
}
err = myMod.AddModelFromRegistry(ctx, base.API, mybase.Model)
if err != nil {
return err
}
err = myMod.AddModelFromRegistry(ctx, navigation.API, mynavigation.Model)
if err != nil {
return err
}
err = myMod.Start(ctx)
defer myMod.Close(ctx)
if err != nil {
return err
}
<-ctx.Done()
return nil
}