Using modules with a git repository on private server

I host my repos on my own server without a code hosting software like gitlab or gitea. When I try to init a project as module I get this error.

hugo mod init juh@myserver.net:hugoexample.git
go: malformed module path "juh@myserver.net:hugoexample.git": invalid char '@'

A similar question was asked here but in Github context.

Is it possible to use a normal git repository at all?

Is your repo public? If so, would you mind posting your test repo link here?

The module path is typically the URL of you repo (without protocol), e.g. myserver.net/hugoexample.

hugo mod init myserver.net/hugoexample

You will see the go-import meta in your repo page.

Some examples.

$ curl https://github.com/hugomods/images?go-get=1 | grep go-import
...
<meta name="go-import" content="github.com/hugomods/images git https://github.com/hugomods/images.git">
...

$ curl https://codeberg.org/razonyang/hugo-mod-hello.git?go-get=1 | grep go-import
...
<meta name="go-import" content="codeberg.org/razonyang/hugo-mod-hello git https://codeberg.org/razonyang/hugo-mod-hello.git.git">
...

Some references:

If your repo is private, I’d suggest

  1. creating a test public repo for making sure everything is OK on your self-hosted Git server,
  2. and then create your private repo, to see how to authenticate with your self-hosted Git server.

I use .netrc on my workflow to authenticate with GitHub for my private modules, you may find more approaches on Google with go modules private repo.

// my build script
echo "machine github.com login $GITHUB_USER password $GITHUB_TOKEN" >> $HOME/.netrc
hugo

I only have ssh access to the repo, no https.

@razon is right – the above is correct. Any authentication (e.g. username) needs to live elsewhere, e.g. in your Git config:

	
[url "ssh://juh@myserver.net"]
	insteadOf = myserver.net

Or something.

1 Like