FirstInGo_01安装、环境变量、工作区和Go Modules

该系列为对Golang(go1.12.9)初入学习时,个人知识体系下认为重要部分的笔记整理。参考学习资料如下:

1、"The Go Programming Language" http://www.gopl.io

2、《Go语言实战》

3、极客时间《Go语言核心36讲》

更多学习可详见:《Go语言核心36讲》笔记2:Golang工作区和GOPATH

安装

golang项目:https://github.com/golang

window: https://download.csdn.net/psearch/0/10/0/2/1/go1.11.1.windows-amd64.msi 或者 https://studygolang.com/ 

IDE:  Goland  或 idea+go plugin 或  https://blog.csdn.net/rudyn/article/details/73824963

环境变量与工作区

GOROOT:Go 语言安装根目录的路径,也就是 GO 语言的安装路径。

GOPATH:若干工作区目录的路径。是我们自己定义的工作空间。

GOBIN:GO 程序生成的可执行文件(executable file)的路径。

Go 语言源码的组织方式就是以环境变量 GOPATH、工作区、src目录和代码包为主线的,详见:代码组织

Go Modules(vgo)

在GoLand创建modules: https://www.jetbrains.com/help/go/create-a-project-with-vgo-integration.html

maven已经支持了go modules构建,参考:

      <plugin>
        <groupId>com.igormaznitsa</groupId>
        <artifactId>mvn-golang-wrapper</artifactId>
        <extensions>true</extensions>
        <configuration>
          <useEnvVars>true</useEnvVars>
          <disableSSLcheck>true</disableSSLcheck>
          <targetArch>amd64</targetArch>
          <resultFolder>${product.path}</resultFolder>
          <sources>${basedir}/src/go</sources>
          <env>
            <GOPROXY>${go.proxy}</GOPROXY>
            <GO111MODULE>on</GO111MODULE>
          </env>
        </configuration>
        <executions>
          <execution>
            <id>default-clean</id>
          </execution>
          <execution>
            <id>default-build</id>
            <phase>package</phase>
            <configuration>
              <resultName>${target.name}</resultName>
              <targetOs>linux</targetOs>
              <packages>
                <main>./main.go</main>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>windows-build</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <resultName>${target.name}.exe</resultName>
              <targetOs>windows</targetOs>
              <packages>
                <main>./main.go</main>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>default-test</id>
            <configuration>
              <skip>true</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>

module是一个相关Go包的集合,它是源代码更替和版本控制的单元。模块由源文件形成的go.mod文件的根目录定义,包含go.mod文件的目录也被称为模块根。moudles取代旧的的基于GOPATH方法来指定在工程中使用哪些源文件或导入包。

详见:https://github.com/golang/go/wiki/Modules 

也可以参照Tonybai的初窥Go module 一文,入手go module和理解Minimal Version Selection https://tonybai.com/2018/07/15/hello-go-module/

go modules最大进步在什么地方?从其原理和作用等维度看,欢迎留言讨论。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值