-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_input_call_test.go
More file actions
executable file
·54 lines (41 loc) · 1.06 KB
/
example_input_call_test.go
File metadata and controls
executable file
·54 lines (41 loc) · 1.06 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
50
51
52
53
54
// +build example
package thingiverseio_test
import (
"log"
"github.com/ThingiverseIO/thingiverseio"
)
const descriptor = `
function SayHello(Greeting string) (Answer string)
tag example_tag
`
// SayHelloInput represents the input parameters for the SayHello function.
type SayHelloInput struct {
Greeting string
}
// SayHelloOutput represents the output parameters for the SayHello function.
type SayHelloOutput struct {
Answer string
}
// ExampleInputCall demonstrates a simple input using the CALL mechanism.
func Example_inputCall() {
// Create and run the input.
i, err := thingiverseio.NewInput(descriptor)
if err != nil {
log.Fatal(err)
}
i.Run()
// Create the request parameter.
p := SayHelloInput{"Greetings, this is a CALL example"}
// Do the call and get a channel for receiving the result
f, err := i.Call("SayHello", p)
if err != nil {
log.Fatal(err)
}
c := f.AsChan()
// Receive the result.
result := <-c
// Decode and print the result.
var out SayHelloOutput
result.Decode(&out)
log.Println("Received an answer:", out.Answer)
}