golang 1.12导入相对目录模块

时间:2019-03-11 04:37:36

标签: go module

转到1.12如何导入相对路径模块。 例如

public class BMI {
    private double height;
    private double weight;
    private String name;
    private double bmi;

    public BMI(String name, double height, double weight) {
        this.name = name;
        this.height = height;
        this.weight = weight;
        this.bmi = weight / (height * height);
    }

    @Override
    public String toString() {
        return name + " is " + height + "m tall and is " + weight + "Kg and has a BMI of " + bmi + "Kg/m^2";
    }
}

我尝试在main.go中导入“ ./demo”,但报告错误消息: 找不到路径_ / home / xxx / mywork / go_project / grpc_demo / demo的模块 如何在main.go中导入演示

1 个答案:

答案 0 :(得分:-1)

  • GO 首先要从$ GOPATH env导入软件包。如果执行找不到包,则会引发错误。

  • 将我们的项目目录添加到 $ GOPATH 环境中。


 <include
        layout="@layout/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

debug@ulab:/tmp/test$ go run main.go
main.go:3:8: cannot find package "mylib" in any of:
    /home/debug/.golang/go/src/mylib (from $GOROOT)
    /home/debug/.golang/gopath/src/mylib (from $GOPATH)

$ tree
.
├── main.go
├── src
│   └── hello
│       └── hello.go
└── start.sh

2 directories, 3 files

$ cat start.sh
#!/bin/sh

GOPATH="$(pwd):$(go env GOPATH)"

go run main.go