Skip to content

Commit 6a8875d

Browse files
committed
docs: clean up options
1 parent e946c7c commit 6a8875d

11 files changed

Lines changed: 982 additions & 1053 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.idea
1+
.idea
2+
AGENTS.md
3+
SPECIFICATION.md

README.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -881,43 +881,9 @@ _ = httpx.Post[any, string](c, "https://example.com/upload", nil,
881881
UploadProgress enables a default progress spinner and bar for uploads.
882882

883883
```go
884-
startServer := func(delay time.Duration) *httptest.Server {
885-
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
886-
defer r.Body.Close()
887-
buf := make([]byte, 32*1024)
888-
for {
889-
if _, err := r.Body.Read(buf); err != nil {
890-
if err == io.EOF {
891-
break
892-
}
893-
return
894-
}
895-
time.Sleep(delay)
896-
}
897-
w.WriteHeader(http.StatusOK)
898-
}))
899-
}
900-
tempFile := func(size int) string {
901-
tmp, err := os.CreateTemp("", "httpx-upload-*.bin")
902-
if err != nil {
903-
return ""
904-
}
905-
_, _ = tmp.Write(make([]byte, size))
906-
_ = tmp.Close()
907-
return tmp.Name()
908-
}
909-
910-
srv := startServer(10 * time.Millisecond)
911-
defer srv.Close()
912-
path := tempFile(4 * 1024 * 1024)
913-
if path == "" {
914-
return
915-
}
916-
defer os.Remove(path)
917-
918884
c := httpx.New()
919-
_ = httpx.Post[any, string](c, srv.URL+"/upload", nil,
920-
httpx.File("file", path),
885+
_ = httpx.Post[any, string](c, "https://example.com/upload", nil,
886+
httpx.File("file", "/tmp/report.bin"),
921887
httpx.UploadProgress(),
922888
)
923889
```

examples/uploadprogress/main.go

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,15 @@
33

44
package main
55

6-
import (
7-
"github.com/goforj/httpx"
8-
"io"
9-
"net/http"
10-
"net/http/httptest"
11-
"os"
12-
"time"
13-
)
6+
import "github.com/goforj/httpx"
147

158
func main() {
169
// UploadProgress enables a default progress spinner and bar for uploads.
1710

1811
// Example: upload with automatic progress
19-
startServer := func(delay time.Duration) *httptest.Server {
20-
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21-
defer r.Body.Close()
22-
buf := make([]byte, 32*1024)
23-
for {
24-
if _, err := r.Body.Read(buf); err != nil {
25-
if err == io.EOF {
26-
break
27-
}
28-
return
29-
}
30-
time.Sleep(delay)
31-
}
32-
w.WriteHeader(http.StatusOK)
33-
}))
34-
}
35-
tempFile := func(size int) string {
36-
tmp, err := os.CreateTemp("", "httpx-upload-*.bin")
37-
if err != nil {
38-
return ""
39-
}
40-
_, _ = tmp.Write(make([]byte, size))
41-
_ = tmp.Close()
42-
return tmp.Name()
43-
}
44-
45-
srv := startServer(10 * time.Millisecond)
46-
defer srv.Close()
47-
path := tempFile(4 * 1024 * 1024)
48-
if path == "" {
49-
return
50-
}
51-
defer os.Remove(path)
52-
5312
c := httpx.New()
54-
_ = httpx.Post[any, string](c, srv.URL+"/upload", nil,
55-
httpx.File("file", path),
13+
_ = httpx.Post[any, string](c, "https://example.com/upload", nil,
14+
httpx.File("file", "/tmp/report.bin"),
5615
httpx.UploadProgress(),
5716
)
5817
}

0 commit comments

Comments
 (0)