...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package curl
17
18 import (
19 "fmt"
20 "net/http"
21 "strings"
22 )
23
24
25
26 func Example_renderCommands() {
27 commands, _ := renderCommands(CommandFlags{
28 Method: http.MethodGet,
29 URL: "https://github.com/chaos-mesh/chaos-mesh",
30 Header: nil,
31 Body: "",
32 FollowLocation: true,
33 JsonContent: false,
34 })
35
36 fmt.Println(strings.Join(commands, " "))
37
38 }
39
40 func Example_renderCommands_withCustomHeader() {
41 commands, _ := renderCommands(CommandFlags{
42 Method: http.MethodGet,
43 URL: "https://github.com/chaos-mesh/chaos-mesh",
44 Header: Header{
45 "User-Agent": []string{"Go-http-client/1.1"},
46 },
47 Body: "",
48 FollowLocation: true,
49 JsonContent: false,
50 })
51
52 fmt.Println(strings.Join(commands, " "))
53
54 }
55
56 func Example_renderCommands_postJson() {
57 commands, _ := renderCommands(CommandFlags{
58 Method: http.MethodPost,
59 URL: "https://jsonplaceholder.typicode.com/posts",
60 Header: nil,
61 Body: "{\"foo\": \"bar\"}",
62 FollowLocation: false,
63 JsonContent: true,
64 })
65
66 fmt.Println(strings.Join(commands, " "))
67
68 }
69