forked from speakeasy-api/speakeasy-auth-test-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice.go
More file actions
67 lines (53 loc) · 1.31 KB
/
service.go
File metadata and controls
67 lines (53 loc) · 1.31 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
package jsonLines
import (
"fmt"
"net/http"
"time"
)
func pushEvents(rw http.ResponseWriter, events [][]string) {
for _, event := range events {
for _, line := range event {
fmt.Fprint(rw, line)
}
if f, ok := rw.(http.Flusher); ok {
f.Flush()
}
time.Sleep(100 * time.Millisecond)
}
}
func pushChunks(rw http.ResponseWriter, chunks []string) {
for _, chunk := range chunks {
fmt.Fprint(rw, chunk)
if f, ok := rw.(http.Flusher); ok {
f.Flush()
}
time.Sleep(100 * time.Millisecond)
}
}
func HandleJSONLinesChunksRich(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "application/jsonl")
pushChunks(rw, []string{
"{\"name\": \"Peter\", \"skills\": [\"Go\"",
", \"Python\"]}\n{\"name\": \"John\"",
", \"skills\": [\"Go\", \"Rust\"]}\n",
})
}
func HandleJSONLinesRich(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "application/jsonl")
pushEvents(rw, [][]string{
{
"{\"name\": \"Peter\", \"skills\": [\"Go\", \"Python\"]}\n",
},
{
"{\"name\": \"John\", \"skills\": [\"Go\", \"Rust\"]}\n",
},
})
}
func HandleJsonLinesDeserializationVerification(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "application/jsonl")
pushEvents(rw, [][]string{
{
"{\"isFinished\": \"yes\"}\n",
},
})
}