| 2301 | } |
| 2302 | |
| 2303 | func ExamplePipe_Do() { |
| 2304 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2305 | data, err := io.ReadAll(r.Body) |
| 2306 | if err != nil { |
| 2307 | log.Fatal(err) |
| 2308 | } |
| 2309 | fmt.Fprintf(w, "You said: %s", data) |
| 2310 | })) |
| 2311 | defer ts.Close() |
| 2312 | req, err := http.NewRequest(http.MethodGet, ts.URL, strings.NewReader("hello")) |
| 2313 | if err != nil { |
| 2314 | log.Println(err) |
| 2315 | return |
| 2316 | } |
| 2317 | script.NewPipe().Do(req).Stdout() |
| 2318 | // Output: |
| 2319 | // You said: hello |
| 2320 | } |
| 2321 | |
| 2322 | func ExamplePipe_EachLine() { |
| 2323 | script.File("testdata/test.txt").EachLine(func(line string, out *strings.Builder) { |