golang初始化脚本

@echo off

rem 环境变量定义
set BASE_PATH=%~dp0
set REAL_GOROOT=%BASE_PATH%GOROOT\go1.10.2\
set REAL_GOPATH=%BASE_PATH%GOPATH\
set DEST_GOROOT=c:\go
set DEST_GOPATH=c:\gopath

rem 打印变量
echo ========================== 环境变量 ================================
echo 当前目录为%BASE_PATH%
echo 将【%REAL_GOROOT%】链接至【%DEST_GOROOT%】
echo 将【%REAL_GOPATH%】链接至【%DEST_GOPATH%】
echo ================================================================
echo 按任意键开始
pause

echo 开始执行....

if exist %DEST_GOROOT% (
    echo 【%DEST_GOROOT%】 已存在,即将删除
    rd /s /Q %DEST_GOROOT%
) else (
    echo 【%DEST_GOROOT%】 不存在
)
mklink /J "%DEST_GOROOT%" "%REAL_GOROOT%"
::如果有的话,先删除GOROOT
wmic ENVIRONMENT where "name='GOROOT'" delete
::创建GOROOT
::wmic ENVIRONMENT create name="GOROOT",username="<system>",VariableValue="%DEST_GOROOT%"
wmic ENVIRONMENT create name="GOROOT",username="%username%",VariableValue="%DEST_GOROOT%"


if exist %DEST_GOPATH% (
    echo 【%DEST_GOPATH%】 已存在,即将删除
    rd /s /Q %DEST_GOPATH%
) else (
    echo 【%DEST_GOPATH%】 不存在
)
mklink /J "%DEST_GOPATH%" "%REAL_GOPATH%"
::如果有的话,先删除GOPATH
wmic ENVIRONMENT where "name='GOPATH'" delete
::创建GOPATH
::wmic ENVIRONMENT create name="GOPATH",username="<system>",VariableValue="%DEST_GOPATH%"
wmic ENVIRONMENT create name="GOPATH",username="%username%",VariableValue="%DEST_GOPATH%"

echo 执行完成,请手动在环境变量PATH中添加【%DEST_GOROOT%\bin】
echo 按任意键结束
pause

标签: golang