/
main.go
51 lines (37 loc) · 912 Bytes
/
main.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
package main
import (
"context"
"fmt"
"log"
"github.com/bahner/go-ma-actor/ui/web"
"github.com/bahner/go-ma-actor/p2p"
)
const defaultProfileName = "robot"
// Run the pong actor. Cancel it from outside to stop it.
func main() {
ctx := context.Background()
initConfig(defaultProfileName)
// THese are the relay specific parts.
p, err := p2p.Init(p2p.DefaultOptions())
if err != nil {
fmt.Printf("Failed to initialize p2p: %v\n", err)
return
}
go p.StartDiscoveryLoop(ctx)
i, err := NewRobot()
if err != nil {
log.Fatal(err)
}
i.Robot.HelloWorld(ctx)
// i.Robot.HelloWorld(ctx, a)
fmt.Println("Press Ctrl-C to stop.")
h := web.NewEntityHandler(p, i.Robot.Entity)
go web.Start(h)
for {
// A background loop that does nothing.
// The ctx will never be cancelled, so this will run forever.
<-ctx.Done()
fmt.Println("Pong run loop cancelled, exiting...")
return
}
}