- vừa được xem lúc

Get dependencies from private repositories

0 0 14

Người đăng: VND

Theo Viblo Asia

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

Bình luận

Bài viết tương tự

- vừa được xem lúc

gRPC - Nó là gì và có nên sử dụng hay không?

Nhân một ngày rảnh rỗi, mình ngồi đọc lại RPC cũng như gRPC viết lại để nhớ lâu hơn. Vấn đề là gì và tại sao cần nó .

0 0 112

- vừa được xem lúc

Embedded Template in Go

Getting Start. Part of developing a web application usually revolves around working with HTML as user interface.

0 0 40

- vừa được xem lúc

Tạo Resful API đơn giản với Echo framework và MySQL

1. Giới thiệu.

0 0 44

- vừa được xem lúc

Sử dụng goquery trong golang để crawler thông tin các website Việt Nam bị deface trên mirror-h.org

. Trong bài viết này, mình sẽ cùng mọi người khám phá một package thu thập dữ liệu có tên là goquery của golang. Mục tiêu chính của chương trình crawler này sẽ là lấy thông tin các website Việt Nam bị deface (là tấn công, phá hoại website, làm thay đổi giao diện hiển thị của một trang web, khi người

0 0 218

- vừa được xem lúc

Tạo ứng dụng craw dữ liệu bing với Golang, Mysql driver

Chào mọi người . Lâu lâu ta lại gặp nhau 1 lần, để tiếp tục series chia sẻ kiến thức về tech, hôm nay mình sẽ tìm hiểu và chia sẻ về 1 ngôn ngữ đang khá hot trong cộng đồng IT đó là Golang.

0 0 59

- vừa được xem lúc

Golang: Rest api and routing using MUX

Routing with MUX. Let's create a simple CRUD api for a blog site. # All . GET articles/ .

0 0 39