-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_example_test.go
More file actions
49 lines (42 loc) · 1.09 KB
/
api_example_test.go
File metadata and controls
49 lines (42 loc) · 1.09 KB
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
package core_test
import (
"context"
. "dappco.re/go/core"
)
func ExampleAPI_RegisterProtocol() {
c := New()
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
return &mockStream{response: []byte("pong")}, nil
})
Println(c.API().Protocols())
// Output: [http]
}
func ExampleAPI_Stream() {
c := New()
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
return &mockStream{response: []byte(Concat("connected to ", h.Name))}, nil
})
c.Drive().New(NewOptions(
Option{Key: "name", Value: "charon"},
Option{Key: "transport", Value: "http://10.69.69.165:9101"},
))
r := c.API().Stream("charon")
if r.OK {
stream := r.Value.(Stream)
resp, _ := stream.Receive()
Println(string(resp))
stream.Close()
}
// Output: connected to charon
}
func ExampleCore_RemoteAction() {
c := New()
// Local action
c.Action("status", func(_ context.Context, _ Options) Result {
return Result{Value: "running", OK: true}
})
// No colon — resolves locally
r := c.RemoteAction("status", context.Background(), NewOptions())
Println(r.Value)
// Output: running
}