mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Go module vendor #5

Open mtchuyen opened 3 years ago

mtchuyen commented 3 years ago

Check Go Env

cmd: go env

Find:

GO111MODULE=on                

Setup repo private

-----> export GOPRIVATE="lab.xxx.vn"

or

Using GONOSUMDB

Gặp các thư viện quá cũ, không con open trên repo (gitlab,...) thì sử dụng env:

GOPROXY=direct

Step 1:

export GO111MODULE=on && go mod init && go mod vendor

or

go mod init 

mtchuyen commented 3 years ago

Glide

With exists

$> glide cc
$> glide up
mtchuyen commented 3 years ago

Lỗi thư viện log Sirupsen

go: github.com/Sirupsen/logrus@v1.5.0: parsing go.mod:
    module declares its path as: github.com/sirupsen/logrus
            but was required as: github.com/Sirupsen/logrus

Solution:

replace github.com/Sirupsen/logrus v1.5.0 => github.com/sirupsen/logrus v1.5.0

mtchuyen commented 3 years ago

Working with Go sub module as a library

https://rashadansari.medium.com/working-with-go-sub-module-as-a-library-93e5db59a0f2

mtchuyen commented 2 years ago

artifact

Gặp lỗi: artifacts not found

Uploading artifacts...
WARNING: /build/Project*.zip: no matching files

The path of artifacts has to be relative to and be a child of $CI_PROJECT_DIR.

    - echo $CI_PROJECT_DIR
    - ls -la $CI_PROJECT_DIR
    - mkdir -pv $CI_PROJECT_DIR/binary
    - cp <<binary_file_after_compile>> $CI_PROJECT_DIR/binary/
    - ls -la $CI_PROJECT_DIR/
    - ls -la $CI_PROJECT_DIR/binary
  artifacts:
    name: binary-<<binary_file_after_compile>>
    paths:
      - binary/<<binary_file_after_compile>>
    expire_in: 1 week
mtchuyen commented 2 years ago

artifact

Gặp lỗi: artifacts not found

Uploading artifacts...
WARNING: /build/Project*.zip: no matching files

The path of artifacts has to be relative to and be a child of $CI_PROJECT_DIR.

  script:
    - echo $CI_PROJECT_DIR
    - ls -la $CI_PROJECT_DIR
    - mkdir -pv $CI_PROJECT_DIR/binary
    - cp <<binary_file_after_compile>> $CI_PROJECT_DIR/binary/
    - ls -la $CI_PROJECT_DIR/
    - ls -la $CI_PROJECT_DIR/binary
  artifacts:
    name: binary-<<binary_file_after_compile>>
    paths:
      - binary/<<binary_file_after_compile>>
    expire_in: 1 week
mtchuyen commented 7 months ago

Difference Between “go get” and “go install” in Go

When working with the Go programming language, developers often come across two important commands: go get and go install. While both commands are related to managing dependencies and building packages, they have distinct purposes. In this article, we will explore the differences between these two commands and understand when to use each of them.

go get

Fetching and Updating Remote Packages. The go get command is primarily used for retrieving remote packages from version control repositories and making them available for use in your projects.

When you run go get, Go downloads the source code of the package and its dependencies within your workspace's bin and pkg directories.

Additionally, go get can also update packages to their latest versions if you have already installed them.

go install

The go install command operates on the local codebase residing in your development environment. It compiles and installs the package present in your local code repository (typically in the GOPATH). If the package has not been fetched yet or if there are updates available, go install will fetch the necessary remote packages and their dependencies, compile them, and install the resulting binaries in the appropriate location within your workspace's bin directory. Therefore, go install can fetch remote packages if required.

For installing executables, go get is deprecated since go 1.17 and go install is the only viable option to acquire executables.