Instructions for using golang package management glide under window

  1. glide installation

    go get github.com/Masterminds/glide
    After the installation is complete, there will be a glide.exe file in the %GOPATH%/bin directory
  2. Configure the environment variables of glide to facilitate the use of glide commands later
  3. Switch to the project root directory to initialize the yaml file with the glide init command

    glide init


    After initialization, the complete directory is as follows

    glide.yaml, because there is only fmt.Println("hello world") in main.go for the time being

    package: github.com/nickchou/glide-go
    import: []
  4. lead a package test

    glide get github.com/mattn/go-adodb

    If the following error is reported (as shown in the figure):
    Unable to export dependencies to vendor directory: Error moving files: exit status 1. output:

    Solution: Find %GOPATH%/src/github.com/Masterminds/glide/path/winbug.go file, modify about 75 lines

    func CustomRename(o, n string) error {
    
    // Handking windows cases first
    if runtime.GOOS == "windows" {
        msg.Debug("Detected Windows. Moving files using windows command")
        //cmd := exec.Command("cmd.exe", "/c", "move", o, n)
        cmd := exec.Command("cmd.exe", "/c", "xcopy /s/y", o, n+"\\") //新增这一行代码
        output, err := cmd.CombinedOutput()
        if err != nil {
            return fmt.Errorf("Error moving files: %s. output: %s", err, output)
        }
    
        return nil
    } else if detectWsl() {
        cmd := exec.Command("mv", o, n)
        output, err2 := cmd.CombinedOutput()
        msg.Debug("Detected Windows Subsystem for Linux. Removing files using subsystem command")
        if err2 != nil {
            return fmt.Errorf("Error moving files: %s. output: %s", err2, output)
        }
    
        return nil
    }
    
    return os.Rename(o, n)
    }
    After recompiling, copy the glide.exe file to the %GOPATH%/bin directory [Important]
  5. Re-import the package. If this package is used in the main function, and the package contains other project sources, it will also be downloaded. Be careful , especially if the project source is on golang.org

    glide get github.com/mattn/go-adodb

    Import a single package source

    glide get --all-dependencies -s -v github.com/mattn/go-adodb
    The directory structure for importing a single package source is as follows
  6. Import the project according to the specified version number, such as

    glide get github.com/go-sql-driver/mysql#v1.2
    The content of the glide.yaml file is as follows
  7. After the installation is complete, when import is actually used, the code source will be found in the vendor directory first.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324980031&siteId=291194637