Environment: Go Lang version 1.20.2 , Windows 11 x64
cd /d D:\
mkdir temp2023_03_04_learn_go
cd temp2023_03_04_learn_go go mod init github.com/donhuvy/vy_golang_foo
del go.mod mkdir foo
mkdir bar dir cd foo
go mod init github.com/donhuvy/vy_golang_foo cd ..
cd bar
go mod init github.com/donhuvy/vy_golang_bar cd .. tree /f D:\temp2023_03_04_learn_go>tree /f
Folder PATH listing for volume New Volume
Volume serial number is 64DB-B8FB
D:.
├───bar
│ go.mod
│
└───foo go.mod cd foo
git init
git remote add origin https://github.com/donhuvy/vy_golang_foo.git
git branch -M main
git add go.mod
git commit -m"Upload"
git push -u origin main cd ..
cd bar
git init
git remote add origin https://github.com/donhuvy/vy_golang_bar.git
git branch -M main
git add go.mod
git commit -m"Upload"
git push -u origin main
Use CMD, type ...
(3 dots) , press Enter, Create file _netrc , you can add many Git (GitHub, GitLab, BitBucket,etc.) accounts
machine gitlab.com
login donhuvy@outlook.com
password glpat-QEXYf9JnSotNokQj0fBL
machine gitcom.com
login donhuvy@outlook.com
password ghpat-QEXYf9JnSotNokQj0fBL
See more at https://stackoverflow.com/a/6031266
Password generate (token, not plain password): Go to https://github.com/settings/tokens . Choose Personal access tokens, Tokens (classic)
Create 2 private git repositories:
File main.go
package main import "time" type Employee struct { firstName string middleName string lastName string dateOfBirth time.Time
}
Set environment variable: GOPRIVATE
Get dependency
go get -u github.com/donhuvy/foo
A type of error
You must re-open CMD for load new config of netrc file.
go env -w GOPRIVATE=github.com/donhuvy/*
We can edit go environement variable at C:\Users\admin\AppData\Roaming\go\env
Final result, project vy_golang_foo
:
File go.mod
module github.com/donhuvy/vy_golang_foo go 1.20
File main.go
package main2 import "time" type Employee struct { FirstName string MiddleName string LastName string DateOfBirth time.Time
}
Project vy_golang_bar
: File go.mod
module github.com/donhuvy/bar go 1.20 require github.com/donhuvy/vy_golang_foo v0.0.0-20230403043549-406d14f982f7
// Sometime, msut delete this line 5, then press Sync in GoLand.
File main.go
package main import ( "fmt" "github.com/donhuvy/vy_golang_foo"
) func main() { var ss = &main2.Employee{ FirstName: "Van", LastName: "Nguyen", MiddleName: "Bich", } fmt.Println("My first love: ", ss.FirstName, ss.MiddleName, ss.LastName)
} // https://golangbyexample.com/struct-another-package-golang/
source code https://1drv.ms/u/s!Ar6K_3y3TiCPgYZWR9RiU7z27Ownug?e=IiRpI7