Golang module path: Difference between revisions

From wikinotes
Line 83: Line 83:
|}
|}
</blockquote><!-- Sample Configurations -->
</blockquote><!-- Sample Configurations -->
= Examples =
<blockquote>
== Git+SSH Private Module, Using Dynamic NGINX MetaTags ==
<blockquote>
</blockquote><!-- Git+SSH Private Module, Dynamic NGINX MetaTags -->
== Git+SSH Private Module, Substituting URL ==
<blockquote>
{{ WARNING |
nope, did not work, let's use HTTP meta tags }}
Your <code>~/.gitconfig</code> or <code>~/.ssh/config</code> can be used to substitute URLs.<br>
Using this, you can defer requests to your server.
{{ expand
| <code>~/.gitconfig</code>
|
<syntaxhighlight lang="ini">
# ~/.gitconfig
[url "ssh://git@example.com:1234/repos"]
    insteadOf = https://go.foo.com/x
</syntaxhighlight>
}}
{{ expand
| <code>~/.config/go/env</code>
|
<syntaxhighlight lang="bash">
# ~/.config/go/env
GOPRIVATE="go.example.com/x/*"
GONOSUMDB="go.example.com/x/*"
GONOPROXY="go.example.com/x/*"
</syntaxhighlight>
<syntaxhighlight lang="bash">
go env -w 'GOPRIVATE=go.example.com/x/*"'
</syntaxhighlight>
}}
<syntaxhighlight lang="bash">
mkdir myproject
go mod init go.example.com/x/myproject
</syntaxhighlight>
</blockquote><!-- Substitute URL -->
</blockquote><!-- Examples -->

Revision as of 21:50, 19 June 2022

Module paths are used both to locate, and uniquely identify packages.
Downloading packages is normally performed by a lookup in go index,
but the actual src is hosted using a server/service of your choosing.

Notes

URL suffix

Suffix indicating repository type

# Repos supporting multiple protocols will try each in order.
# ex: https://, git://, git+ssh://
#
#
# Bazaar      .bzr
# Fossil      .fossil
# Git         .git
# Mercurial   .hg
# Subversion  .svn

import "example.com/path/to/repo.git"
import "example.com/path/to/repo.git/sub/directory"

HTTP meta tag

HTTP meta tag

<!--
  Meta tags let you abstract the path of your src.
  You may use a import-prefix that has nothing to do with your URL.

  IMPORT-PREFIX: the name of the package being fetched (ex. example.com/x/foo)"
  VCS:           bzr, fossil, git, hg, svn
  REPO-ROOT:     URL to repo-root (no VCS extension!)
-->
<!--                            IMPORT-PREFIX        VCS   REPO-ROOT                 -->
<meta name="go-import" content="example.org/x/foo    git   git+ssh://repos.org:/repos/foo">

Hosted services

Hosted Services

# github.com
import "github.com/user/your_project"
import "github.com/user/your_project/sub/directory"

# launchpad.net
import "launchpad.net/project"
import "launchpad.net/project/series"
import "launchpad.net/project/series/sub/directory"

# ...

Private modules

TODO:

verify you can host your own proxy/checksums

You may use private modules, but you'll need to set environment variables to keep them private.

# ignore checksum checks on these packages
GOPRIVATE=*.corp.example.com,rsc.io/private

# alternatively, define your own proxy with your own checksums
GOPROXY=proxy.example.com
GONOPROXY=none

Sample Configurations

golang private modules conf: meta tags, git+ssh, nginx