Home > Backend Development > Golang > How to Use `go get` with Locally Hosted Git Repositories?

How to Use `go get` with Locally Hosted Git Repositories?

Barbara Streisand
Release: 2024-12-30 13:23:14
Original
885 people have browsed it

How to Use `go get` with Locally Hosted Git Repositories?

Using Go Get with Repositories on Local Servers

Question:

How to use go get with a git repository hosted on a local server?

Answer:

Using Packages and Modules with Local Git Repositories

To use Go packages and modules with git repositories on private servers (IP addresses like 10.xxx.yyy.zzz or 192.168.xxx.yyy), follow these steps:

Prerequisites:

  • Latest Go version with GOPATH set
  • Another computer for creating git repositories (your private git server)
  • SSH key access to the private git server

Setup:

  • Create a directory structure outside your GOPATH and place the dateutil.go and stringutil.go files as shown below:
package
├── github
│   ├── dateutil
│   │   └── src
│   │       └── datepackage
│   │           └── dateutil.go
│   └── stringutil
│       └── src
│           └── stringpackage
│               └── stringutil.go
└── your-local-git-repo-hostname
    ├── dateutil
    │   └── src
    │       └── datepackage
    │           └── dateutil.go
    └── stringutil
        └── src
            └── stringpackage
                └── stringutil.go
Copy after login

Creating Repositories

  • Create bare git repositories on your private git server for both dateutil and stringutil directories.
  • Assign ssh key access to your private git server.
  • Configure your .gitconfig file to use ssh instead of https for private servers:
git config --global url."[email protected]:".insteadOf "https://192.168.0.12/"
Copy after login

Using Git Repositories

  • Copy the dateutil.go and stringutil.go files into the directories under your-local-git-repo-hostname.
  • Create and push the local git repositories to your private git server.

Using go get

  • Add a .git suffix to the repository path when using go get:
go get 192.168.0.12/gitrepo/go-package-test-stringutil.git/stringpackage
go get 192.168.0.12/gitrepo/go-package-test-dateutil.git/datepackage
Copy after login

Key Differences:

When using repositories on a local server versus GitHub:

  • .gitconfig modification
  • .git suffix in go get statements
  • Hostname in go get and import statements must have a dot

The above is the detailed content of How to Use `go get` with Locally Hosted Git Repositories?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template