@@ -3,4 +3,70 @@ title: Go
33description : How to install and use Ada in a Go project
44---
55
6- Ada has a Go client available on [ Github] ( https://github.com/ada-url/goada ) .
6+ Ada has a Go client available on [ GitHub] ( https://github.com/ada-url/goada ) .
7+
8+ ## Requirements
9+
10+ Go 1.24 or better.
11+
12+ ## Installation
13+
14+ ``` bash
15+ go get github.com/ada-url/goada
16+ ```
17+
18+ ## Usage
19+
20+ ``` go
21+ import (
22+ " github.com/ada-url/goada"
23+ " fmt"
24+ )
25+
26+ url , err := goada.New (" https://www.GOogle.com" )
27+ if err != nil {
28+ // handle error
29+ }
30+ fmt.Println (url.Href ()) // https://www.google.com/
31+ url.SetProtocol (" http:" )
32+ url.SetHash (" goada" )
33+ fmt.Println (url.Hash ()) // #goada
34+ fmt.Println (url.Href ()) // http://www.google.com/#goada
35+ ```
36+
37+ ## Why not ` net/url ` ?
38+
39+ Go's built-in ` net/url ` follows RFC 3986 rather than the WHATWG URL standard
40+ used by browsers. This leads to differences in practice:
41+
42+ | String source | Value |
43+ | :---| :---|
44+ | Input | ` https://www.7-Eleven.com/Home/../Privacy/Montréal ` |
45+ | Ada (goada) | ` https://www.xn--7eleven-506c.com/Home/Privacy/Montr%C3%A9al ` |
46+ | Go ` net/url ` | ` https://www.7-Eleven.com/Home/../Privacy/Montr%C3%A9al ` |
47+
48+ Specifically, Go's ` net/url ` :
49+
50+ - Does not normalize hostnames (no IDNA/Punycode encoding)
51+ - Does not process path components (no dot-segment removal)
52+ - Does not encode special characters in query parameters the same way browsers do
53+
54+ ## Performance
55+
56+ Benchmarks against the top 100k URLs dataset:
57+
58+ | Library | ns/op per URL | WHATWG compliant |
59+ | ---| ---| ---|
60+ | ` github.com/ada-url/goada ` | 22.0 | Yes |
61+ | Go ` net/url ` | 19.4 | No |
62+ | ` github.com/nlnwa/whatwg-url ` | 139.0 | Yes |
63+
64+ goada is the fastest WHATWG-compliant URL parser available for Go.
65+
66+ Run ` go test -bench BenchmarkTop100 -run - ` to reproduce these results.
67+
68+ ## Resources
69+
70+ - [ Source code] ( https://github.com/ada-url/goada )
71+ - [ GoDoc] ( https://godoc.org/github.com/ada-url/goada )
72+ - [ Benchmark datasets] ( https://github.com/ada-url/url-various-datasets )
0 commit comments