Debian Codegraph @

ami/connect_demo_test.go

raw symbols SCIP
1 package ami_test
2
3 import (
4 "context"
5 "fmt"
6 "github.com/wenerme/astgo/ami"
7 )
8
9 func ExampleConnect() {
10 boot := make(chan *ami.Message, 1)
11
12 conn, err := ami.Connect(
13 "192.168.1.1:5038",
14 ami.WithAuth("admin", "admin"), // AMI auth
15 // add predefined subscriber
16 ami.WithSubscribe(ami.SubscribeFullyBootedChanOnce(boot)),
17 ami.WithSubscribe(func(ctx context.Context, msg *ami.Message) bool {
18 fmt.Println(msg.Format()) // log everything
19 return true // keep subscribe
20 }, ami.SubscribeSend(), // subscribe send message - default recv only
21 ))
22 if err != nil {
23 panic(err)
24 }
25 <-boot
26 // AMI now FullyBooted
27 _ = conn
28 }