Don't couple your Go code to GitHub(iain.rocks)
322 points by birdculture 16 days ago | 174 comments
tl;dr: Because Go uses import paths that double as fetch locations, using `github.com/...` directly couples your code to a specific git host, making migrations painful (the author cites a company stuck paying for GitHub, GitLab, and Azure DevOps simultaneously). The fix is to use a custom domain (e.g., `go.iain.rocks/boneclone`) that serves Go's `go-import` meta tags, letting you repoint to a different host without breaking consumers. The post includes an Nginx config and HTML template to set this up.
HN Discussion:
  • ↓Custom domains are worse than GitHub because they expire when owners stop paying, risking hijacking
  • ~Package managers fetching code from the internet is fundamentally flawed regardless of host
  • ~Go's import-path-as-URL design is a mistake that the article's workaround only partially addresses
  • ↓The go.mod replace directive already solves migration without needing custom domains
  • ↑Agrees custom domains for namespacing are good practice, applicable beyond just Go