安装GO环境

server/2024/9/23 9:27:36/
#windows
1.下载go的安装包msi,下载完双击运行,指定一个目录进行安装
#msi安装时,会自动设置以下环境变量:
#GOPATH(默认设置为C:\Users\hhx\go),
#C:\Users\hhx\go\bin,
#go安装位置下的bin目录
2.检查是否安装成功,终端中运行go version

解释一些环境变量

GOROOT:go的安装位置(等同于JAVA_HOME)
GOPATH:
#When using modules, GOPATH is no longer used for resolving imports.
#However, it is still used to store downloaded source code(in GOPATH/pkg/mod) and compiled commands(in GOPATH/bin).
#In module-aware mode, GOPATH no longer defines the meaning of imports during a build, but it still stores downloaded
#dependencies(in GOPATH/pkg/mod) and installed commands(in GOPATH/bin, unless GOBIN is set).GO111MODULE:值为on或unset时,go命令以module-aware模式运行(即使没有go.mod文件)
#In module-aware mode, the go command uses go.mod files to find versioned dependencies, and it typically loads
#packages out of the module cache, downloading modules if they are missing.
#In GOPATH mode, the go command ignores modules; it looks in vendor directories and in GOPATH to find dependencies.
GOPROXY:下载第三方module的方式(module proxy server,git等vcs)
GOCACHE:编译产生的中间文件缓存#The go command caches build outputs for reuse in future builds.
GOMODCACHE:下载的module依赖存放位置#A local directory storing downloaded modules, located in GOPATH/pkg/mod.

go项目结构

A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively.

#module
A module is a collection of packages that are released, versioned, and distributed together.
A module is identified by a module path, which is declared in a go.mod file, together with information
about the module’s dependencies. 
The module root directory is the directory that contains the go.mod file.#import
import path和package path一样
A string used to import a package in a Go source file.
#import "lib/math",使用的时候用包名引用,math.Sin
#import m "lib/math",使用的时候用别名引用,m.Sin
#import . "lib/math",直接使用,Sin
import a package solely for its side-effects(initialization), use the blank identifier as explicit package name
#import _ "lib/math"
#package
A package clause begins each source file and defines the package to which the file belongs.
package是一个逻辑概念,和文件所处的目录名没有关系,但一般规范package名字和文件所处目录名一样.同一个目录下的所有源文件通常属于同一个package
一个目录下的源文件可以属于不同的package(如标准库src/fmt目录下,src/time目录下)
一个package内不能有同名的变量(类型不同也不行),也不能有同名的函数(不支持函数重载)
一个package内不同源文件之间的变量,函数可以互相调用A package path is the module path joined with the subdirectory containing the package (relative to the module root).
#module path+package所在目录相对于module root的路径

调试go项目

调试go项目时,delve的版本需要支持使用的go版本
go install github.com/go-delve/delve/cmd/dlv@latest
将生成的dlv.exe替换掉goland中的dlv程序

https://go.dev/doc/install
https://go.dev/wiki/GOPATH
https://pkg.go.dev/cmd/go
https://blog.csdn.net/chushoufengli/article/details/127516201
https://github.com/golang/go/issues/50244
https://youtrack.jetbrains.com/issue/GO-4287
https://stackoverflow.com/questions/20427890/does-it-make-sense-to-have-two-packages-in-the-same-directory
https://youtrack.jetbrains.com/issue/GO-4287/incorrect-multiple-packages-in-directory-with-build-ignore
https://github.com/flycheck/flycheck/issues/676
https://go.dev/ref/mod
https://go.dev/ref/spec
https://go.dev/wiki/
https://pkg.go.dev/cmd/go#hdr-Environment_variables
https://go.dev/ref/mod#module-cache
https://go.dev/doc/go-get-install-deprecation
https://go.dev/doc/modules/managing-dependencies
https://www.reddit.com/r/golang/comments/2xhfwa/is_there_a_way_to_have_two_packages_in_same_folder/
https://stackoverflow.com/questions/59718540/go-mod-init-creating-new-folders-what-is-the-significance-of-path


http://www.ppmy.cn/server/43397.html

相关文章

代码随想录算法训练营day34 | 455.分发饼干、376. 摆动序列、53. 最大子序和

理论基础 贪心的本质是选择每一阶段的局部最优,从而达到全局最优。 刷题或者面试的时候,手动模拟一下感觉可以局部最优推出整体最优,而且想不到反例,那么就试一试贪心。 455.分发饼干 result和j变化一致,可以去除一…

01.爬虫---初识网络爬虫

01.初识网络爬虫 1.什么是网络爬虫2.网络爬虫的类型3.网络爬虫的工作原理4.网络爬虫的应用场景5.网络爬虫的挑战与应对策略6.爬虫的合法性总结 1.什么是网络爬虫 网络爬虫,亦称网络蜘蛛或网络机器人,是一种能够自动地、系统地浏览和收集互联网上信息的程…

Git如何将pre-commit也提交到仓库

我一开始准备将pre-commit提交到仓库进行备份的,但是却发现提交不了,即使我使用强制提交都不行。 (main) $ git add ./.git/hooks/pre-commit(main) $ git status On branch main nothing to commit, working tree clean# 强制提交(main) $ git add -f .…

Shell编程之条件语句

一、条件测试操作 Shell环境根据命令执行后的返回状态值($?)来判断是否执行成功,返回值若为0则成功,不为0则表示失败或异常。有两种专门的测试工具——"test 条件表达式"和"[ 条件表达式 ]"。这两种方式的作用完全相同。根据需要测…

全域运营平台的优缺点各有哪些?听听使用者怎么说!

作为多个创业者交流群内的热点话题,关于全域运营平台优缺点的分析和点评不断涌现,为许多创业者更多信息的同时,也让他们的选择过程变得非常艰难。而在众多的全域运营平台中,被分析和点评次数最多的,当属全域运营平台。…

C#技术生态全景

分类汇总 1.WINFORM. 2.WINFORM - DevExpress. 3.WPF. 4.计算机网络协议。 1.HTTP 协议:超文本传输协议,用于在 Web 上发送和接收数据,是互联网上最常用的协议之一。2.FTP 协议:文件传输协议,用于在不同计算机之间传…

【C++面试100问】第八十五问:有了const,C++11为什么还要引入constexpr

B站讲解视频 在大部分实际场景中,const 和 constexpr 是可以混用的;但是在创建数组用修饰的变量指定size的时候,只能用constexpr;总的来说,在 C 11 标准中,const 用于为修饰的变量添加“只读”属性&#xf…

​​​【收录 Hello 算法】10.6 小结

10.6 小结 二分查找依赖数据的有序性,通过循环逐步缩减一半搜索区间来进行查找。它要求输入数据有序,且仅适用于数组或基于数组实现的数据结构。暴力搜索通过遍历数据结构来定位数据。线性搜索适用于数组和链表,广度优先搜索和深度优先搜索…