From 8b4653769c69a658a5cae6df3798a4f8ad3a60a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleks=20R=C5=ABti=C5=86=C5=A1?= Date: Fri, 14 Feb 2025 03:36:11 +0000 Subject: [PATCH] I did a thing, I'm gonna blog about it --- posts/2025-02-13-go-module-imports.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 posts/2025-02-13-go-module-imports.md diff --git a/posts/2025-02-13-go-module-imports.md b/posts/2025-02-13-go-module-imports.md new file mode 100644 index 0000000..52242eb --- /dev/null +++ b/posts/2025-02-13-go-module-imports.md @@ -0,0 +1,25 @@ +--- +title: Custom import paths for Go modules +published_on: '2025-02-13' +--- + +Go modules are great. URL-based imports, generally, are great. One of the things that makes them so great is that putting them on your own domain provides a good way of verifying ownership without going through a third party or a complicated review process. Plus, it looks cool. + +So, how exactly do you do such a thing? Well, it's [buried in the documentation](https://pkg.go.dev/cmd/go#hdr-Remote_import_paths), but it's really pretty simple. For each import path (e.g. `mysite.com/mypackage`), just put a page on your website with a `go-import` meta tag: + +```html + +``` + +_(`git` can be replaced with `bzr`, `fossil`, `hg`, or `svn` for different VCSs — see the docs page linked above.)_ + +This website, for instance, builds these pages from a hash in [`build.rb`](https://git.farthergate.com/sites/farthergate.com/-/blob/main/build.rb): + +```ruby +def go_modules = { + "farthergate.com/stack" => "https://git.farthergate.com/aleks/stack", + # ... +} +``` + +See [farthergate.com/stack](/stack) for the generated page. Look in the web inspector for the `meta` tag! \ No newline at end of file