Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stbenjam/no-sprintf-host-port
Go linter that checks for URL construction that won't work with IPv6
https://github.com/stbenjam/no-sprintf-host-port
go go-lang go-linter golang golint ipv6 linter
Last synced: 2 months ago
JSON representation
Go linter that checks for URL construction that won't work with IPv6
- Host: GitHub
- URL: https://github.com/stbenjam/no-sprintf-host-port
- Owner: stbenjam
- License: mit
- Created: 2022-04-06T20:10:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-13T13:52:42.000Z (over 2 years ago)
- Last Synced: 2024-06-20T07:21:21.986Z (6 months ago)
- Topics: go, go-lang, go-linter, golang, golint, ipv6, linter
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# no-sprintf-host-port
The Go linter no-sprintf-host-port checks that sprintf is not used to
construct a host:port combination in a URL. A frequent pattern is for a
developer to construct a URL like this:```go
fmt.Sprintf("http://%s:%d/foo", host, port)
```However, if "host" is an IPv6 address like `2001:4860:4860::8888`, the
URL constructed will be invalid. IPv6 addresses must be bracketed, like this:```
http://[2001:4860:4860::8888]:9443
```The linter is naive, and really only looks for the most obvious cases, but where
it's possible to infer that a URL is being constructed with Sprintf containing a `:`,
this informs the user to use `net.JoinHostPort` instead.## Thanks
Based on the [`go-printf-func-name`](https://github.com/jirfag/go-printf-func-name) linter,
and this [article](https://disaev.me/p/writing-useful-go-analysis-linter/).