-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
110 lines (80 loc) · 2.26 KB
/
Copy pathexample_test.go
File metadata and controls
110 lines (80 loc) · 2.26 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2026 The Nanoninja Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package render_test
import (
"bytes"
"context"
"os"
"github.com/nanoninja/render"
)
func ExampleBinary() {
_ = render.Binary().Render(context.Background(), os.Stdout, []byte("binary content"), render.NoOptions)
// Output:
// binary content
}
func ExampleText() {
_ = render.Text().Render(context.Background(), os.Stdout, "Hello, Gopher!", render.NoOptions)
// Output:
// Hello, Gopher!
}
func ExampleJSON() {
data := map[string]string{"message": "hello"}
_ = render.JSON().Render(context.Background(), os.Stdout, data, render.NoOptions)
// Output:
// {"message":"hello"}
}
func ExampleYAML() {
data := map[string]string{"message": "hello"}
_ = render.YAML().Render(context.Background(), os.Stdout, data, render.NoOptions)
// Output:
// message: hello
}
func ExampleHTML() {
_ = render.HTML().Render(context.Background(), os.Stdout, "<h1>Hello</h1>", render.NoOptions)
// Output:
// <h1>Hello</h1>
}
func ExampleMulti() {
var log bytes.Buffer
_ = render.Multi(render.JSON(), &log).Render(context.Background(), os.Stdout, map[string]string{
"key": "value",
}, render.NoOptions)
// Output:
// {"key":"value"}
}
func ExamplePipe() {
_ = render.Pipe(
render.Text(),
).Render(context.Background(), os.Stdout, "Hello", render.NoOptions)
// Output:
// Hello
}
func ExampleMarkdown() {
_ = render.Markdown().Render(context.Background(), os.Stdout, "# Hello", render.NoOptions)
// Output:
// <h1>Hello</h1>
}
func ExampleGzip() {
var buf bytes.Buffer
_ = render.Pipe(
render.JSON(),
render.Gzip(),
).Render(context.Background(), &buf, map[string]string{"message": "hello"}, render.NoOptions)
}
func ExampleCache() {
r := render.Cache(render.JSON())
_ = r.Render(context.Background(), os.Stdout, "hello", render.NoOptions)
_ = r.Render(context.Background(), os.Stdout, "hello", render.NoOptions)
// Output:
// "hello"
// "hello"
}
func ExampleNewCache() {
r := render.NewCache(render.JSON(), render.CacheConfig{
TTL: 5 * 60 * 1000000000,
})
_ = r.Render(context.Background(), os.Stdout, map[string]string{"status": "ok"}, render.NoOptions)
// Output:
// {"status":"ok"}
}