-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate_test.go
56 lines (53 loc) · 1.08 KB
/
template_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
package main
import (
"fmt"
rpc "github.com/hashicorp/serf/client"
"io/ioutil"
)
func ExampleRenderTemplate() {
members := []rpc.Member{
{
Name: "web-1",
Addr: []byte{172, 16, 0, 21},
Port: 7946,
Status: "alive",
Tags: map[string]string{
"app": "nginx",
"webport": "8080",
},
},
{
Name: "web-2",
Addr: []byte{172, 16, 0, 22},
Port: 7946,
Status: "alive",
Tags: map[string]string{
"app": "nginx",
"webport": "8080",
},
},
{
Name: "web-3",
Addr: []byte{172, 16, 0, 23},
Port: 7946,
Status: "alive",
Tags: map[string]string{
"app": "httpd",
"webport": "80",
},
},
}
RenderTemplate("test/template_1.tpl", "test/result_1.txt", members)
out, err := ioutil.ReadFile("test/result_1.txt")
if err != nil {
panic(err)
}
fmt.Println(string(out))
// Output:
// BEGIN
// server web-1 at 172.16.0.21 with serf at 7946 and nginx at 8080
// server web-2 at 172.16.0.22 with serf at 7946 and nginx at 8080
// server web-3 at 172.16.0.23 with serf at 7946 and httpd at 80
//
// END
}