Benjamin

静以修身,俭以养德,非澹薄无以明志,非宁静无以致远。
随笔 - 386, 文章 - 0, 评论 - 196, 引用 - 0
数据加载中……

golang语言开发概述(win10)

安装包下载地址为:https://golang.org/dl/或者https://golang.google.cn/dl/
Windows 下可以使用 .msi 后缀文件
设置代理:go env -w GOPROXY=https://goproxy.cn,direct
常用的代理地址如下:
https://goproxy.io
https://goproxy.cn
https://mirrors.aliyun.com/go...
https://mirrors.cloud.tencent...
https://athens.azurefd.net
https://gocenter.io
(注:Go语言官方已推出官方模块代理 https://proxy.golang.org 但目前国内处于被墙状态。)
或者自建模块代理工具:
https://github.com/goproxyio/...
https://github.com/goproxy/go...
https://github.com/gomods/athens
go env
设置GOROOT(go安装目录下bin路径) GOPATH(工作目录)
bin文件夹存放go install命名生成的可执行文件,可以把$GOPATH/bin路径加入到PATH环境变量里,就和我们上面配置的$GOROOT/bin一样,这样就可以直接在终端里使用我们go开发生成的程序了。
pkg文件夹是存在go编译生成的文件。
src存放的是我们的go源代码,不同工程项目的代码以包名区分。
在go工程源码目录下运行go mod init [module name],zai pkg下会产生一个mod文件夹,
此时输入go test语句,根据需要的依赖自动生成require,也就是依赖包
用go get github.com/garyburd/redigo/redis会下载依赖包  末尾加@符号,用来指定版本
go install  main.go  在bin目录下生成exe文件;
go build main.go 也会生成exe文件
go程序基本机构
package main - 每一个go程序必须以 package name 开头. 包的设计主要用来做代码隔离和代码可复用. 这段程序里面的包名叫做 main
func main() - main函数是一个特殊的函数. 应用程序从main函数开始执行.
main 函数必须被放在main包中. The { and } indicate the start and end of the main function.
import关键字是导入包(库)

posted on 2021-03-27 14:31 Benjamin 阅读(165) 评论(0)  编辑 收藏 引用 所属分类: 杂谈


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理