我用go1.3.1.windows-amd64.msi安装go,在安装GOROOT是默认设置后,我找到了 在PATH中D:\ Programs \ Go \ bin,然后我创建一个GOPATH环境变体, 当使用' go get'命令,发生错误:
包github.com/coreos/etcd:无法下载,$ GOPATH一定不能设置为$ GOROOT。有关详细信息,请参阅:go help gopath
操作系统:Windows 7
GOPATH会与GOROOT发生冲突吗?
如何设置这两个PATH值?
答案 0 :(得分:25)
GOROOT
必须引用您安装GO的文件夹GOPATH
必须引用一个空文件夹,该文件夹将是 workspace (src / pkg / bin用于您的项目)在用户环境变量中添加这两个变量。
go get github.com/coreos/etcd
应该:
%GOPATH%/src/github.com/coreos/etcd
中的来源(src
为您创建)%GOPATH%/pkg/windows_amd64
中编译(pkg/
是为您创建的,windows_amd64
反映了您的Windows架构)go install
,将其安装在%GOPATH%/bin
中(bin/
也是为您创建的)注意:使用Go 1.8+(2017年第2季度),默认情况下({在Windows上)GOPATH
可能会为您设置%USERPROFILE%/go
。
在Linux上,它将是 $HOME/go
:请参阅issue 17262。
三年后更新2018年:GOPATH
已经过时了 Go 1.11 modules :
mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject
答案 1 :(得分:4)
我遇到了同样的问题。但是,我按照教程中的说法设置了所有内容,但忘记重新启动cmd
。所以步骤是:
Go
分发(自动设置GOROOT
变量)bin
,src
和pkg
->
所有控制面板项 ->
系统 ->
< strong> Advansed System Settings ->
标签高级 ->
环境变量 ->
点击系统可变性 ->
变量名称= GOPATH
,变量值= Your:\directory\that\you\created
cmd
或Bash
(重要)并设置GOPATH
。要确保运行go env
,您就会看到自己的价值。答案 2 :(得分:0)
您不应设置$GOROOT
。
键入export GOROOT=""
以解决您的问题。
答案 3 :(得分:0)
// when this Observable emits, the concurrency is recalculated
const mySwitch = new Subject<number>();
let myConcurrency = 1;
// this block emits five times, every time setting a new value for the concurrency
// and the making mySwitch emit
merge(interval(1000).pipe(map(i => i + 2)), of(1))
.pipe(
delay(0),
take(5),
tap(i => {
myConcurrency = i * 2;
console.log("switch emitted", i);
mySwitch.next(i);
})
)
.subscribe();
// source is an hot Observable which emits an incresing number every 100 ms
const source = new Subject<number>();
interval(100)
.pipe(take(100))
.subscribe(i => source.next(i));
// this is the core of the logic
// every time mySwitch emits the old subscription is cancelled and a new one is created
mySwitch
.pipe(
switchMap(() =>
// defer is critical here since we want a new Observable to be generated at subscription time
// so that the new concurrency value is actually used
defer(() =>
source.pipe(
mergeMap(
i =>
// this is just a simulation of a an inner Observable emitting something
interval(100).pipe(
delay(100),
map(j => `Observable of ${i} and ${j}`),
take(10)
),
myConcurrency
)
)
)
)
)
.subscribe({
next: data => console.log(data)
});
会完成您的工作。