-
Notifications
You must be signed in to change notification settings - Fork 69
/
example_test.go
71 lines (61 loc) · 1.64 KB
/
example_test.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
61
62
63
64
65
66
67
68
69
70
71
package proteus
import (
"fmt"
"strings"
"time"
"gopkg.in/src-d/proteus.v1/example/client"
"gopkg.in/src-d/proteus.v1/example/server"
)
func ExampleProteus() {
addr := "localhost:8001"
s, err := server.NewServer(addr)
if err != nil {
panic(fmt.Sprintf("could not open server: %s", err))
}
defer s.Stop()
c, err := client.NewClient(addr)
if err != nil {
panic(fmt.Sprintf("could not open client: %s", err))
}
defer c.Close()
n, err := c.RequestRandomNumber(0, 1)
if err != nil {
panic(fmt.Sprintf("could not receive random number: %s", err))
}
fmt.Println(n)
cat, err := c.RequestRandomCategory()
if err != nil {
panic(fmt.Sprintf("could not receive category: %s", err))
}
fmt.Println(cat.CanBuy)
fmt.Println(cat.ShowPrices)
α, err := c.RequestAlphaTime()
if err != nil {
panic(fmt.Sprintf("could not receive alpha time: %s", err))
}
fmt.Printf("%s: %s\n", α.Name, α.Time.Format("Jan 2, 2006 at 3:04pm"))
ω, err := c.RequestOmegaTime()
if err != nil {
panic(fmt.Sprintf("could not receive omega time: %s", err))
}
fmt.Printf("%s: %s\n", ω.Name, ω.Time.Format("Jan 2, 2006 at 3:04pm"))
product, err := c.RequestPhone()
if err != nil {
panic(fmt.Sprintf("could not receive product: %s", err))
}
fmt.Println(product.Name)
fmt.Println(strings.Join(product.Tags, ", "))
duration, err := c.RequestDurationForLength(299792458)
if err != nil {
panic(fmt.Sprintf("could not receive duration: %s", err))
}
fmt.Printf("Duration: %d", duration.Duration/time.Second)
// Output: 4
// true
// true
// alpha: Jan 1, 1970 at 12:00am
// omega: Dec 12, 2012 at 10:30am
// MiPhone
// cool, mi, phone
// Duration: 1
}