• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jeffotoni / quick / 217

05 Mar 2025 11:05PM UTC coverage: 49.111% (-0.4%) from 49.485%
217

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/example/http'

0 of 34 new or added lines in 3 files covered. (0.0%)

1824 of 3714 relevant lines covered (49.11%)

2687.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/example/quick.http.client/postform/main.go
1
package main
2

3
import (
4
        "encoding/json"
5
        "fmt"
6
        "log"
7
        "net/url"
8
        "time"
9

10
        "github.com/jeffotoni/quick"
11
        "github.com/jeffotoni/quick/http/client"
12
)
13

14
func main() {
×
NEW
15
        q := quick.New()
×
NEW
16

×
NEW
17
        // Define a route to process POST form-data
×
NEW
18
        q.Post("/postform", func(c *quick.Ctx) error {
×
NEW
19
                form := c.FormValues()
×
NEW
20
                return c.JSON(map[string]any{
×
NEW
21
                        "message": "Received form data",
×
NEW
22
                        "data":    form,
×
NEW
23
                })
×
NEW
24
        })
×
25

26
        // Start the server in a separate goroutine
NEW
27
        go func() {
×
NEW
28
                fmt.Println("Quick server running at http://localhost:3000")
×
NEW
29
                if err := q.Listen(":3000"); err != nil {
×
NEW
30
                        log.Fatalf("Failed to start Quick server: %v", err)
×
NEW
31
                }
×
32
        }()
33

34
        // Criando um cliente HTTP antes de chamar PostForm
NEW
35
        cClient := client.New(
×
NEW
36
                client.WithTimeout(5*time.Second), // Define um timeout de 5s
×
NEW
37
                client.WithHeaders(map[string]string{
×
NEW
38
                        "Content-Type": "application/x-www-form-urlencoded", // Tipo correto para forms
×
NEW
39
                }),
×
NEW
40
        )
×
NEW
41

×
NEW
42
        // Check if the HTTP client was initialized correctly
×
NEW
43
        if cClient == nil {
×
NEW
44
                log.Fatal("Erro: cliente HTTP não foi inicializado corretamente")
×
NEW
45
        }
×
46

47
        // Declare Values
48
        formData := url.Values{}
×
49
        formData.Set("username", "quick_user")
×
50
        formData.Set("password", "supersecret")
×
51

×
NEW
52
        // Send a POST request
×
NEW
53
        resp, err := cClient.PostForm("http://localhost:3000/postform", formData)
×
54
        if err != nil {
×
55
                log.Fatalf("PostForm request with retry failed: %v", err)
×
56
        }
×
57

58
        // Check if the response is valid
NEW
59
        if resp == nil || resp.Body == nil {
×
NEW
60
                log.Fatal("Erro: resposta vazia ou inválida")
×
NEW
61
        }
×
62

63
        // Unmarshal the JSON response (if applicable)
64
        var result map[string]any
×
65
        if err := json.Unmarshal(resp.Body, &result); err != nil {
×
66
                log.Fatal(err)
×
67
        }
×
68
        fmt.Println("POST response:", result)
×
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc