当前位置:网站首页>Go learning notes (1) environment installation and hello world
Go learning notes (1) environment installation and hello world
2022-07-07 23:54:00 【Raring_ Ringtail】
Time really fast , I have learned 4 More than months go The language . I have loved this language since I first came into contact with it ,go There are many language shadows , Learn quickly and write comfortably . The best thing for me is to use go The written program can package all dependencies into one file , It's very convenient to deploy .
Although with go I've written a lot of code , But there is no systematic study and sorting . Always use what function, go online search . Next, I want to spend a little time studying systematically every day go Language , Write down some experiences and ideas you learned and used , To deepen the go The understanding of the .
If you just want to try go The language of words ,go The official language provides an online programming environment https://go.dev/play/ You can program online directly on the web .

Click after writing Run You can just run it , spot Format The current code will be formatted , If you use VS Code or GoLand The code will be automatically formatted every time the code is saved or compiled .
go The environment installation of is very simple , To https://go.dev/dl/ Just download and install the installer of the corresponding system ,IDE You can use VS Code collocation go Language plug-ins ,VS Code Sometimes there are some small problems when using it , If you want a better programming experience, you can use GoLand,JetBrains Products must be fine .
packed go By default, a go Folder , This is for storing go Some programs and packages of . If you want to change to another directory, you need to modify GOPATH environment variable , Generally, there is no need to modify .
After installation, it can run on the terminal go version To confirm go It's really installed , If the prompt does not find the command , You need to in PATH Add... To the environment variable go Directory of executable programs . Usually in the user folder go/bin/ Under the folder .
When everything is in place , Find a text editor or IDE( Recommend to use GoLand or VS Code), You can start writing code . One of the simplest Hello World The procedure is as follows
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
} Save the code as hello.go , Run at terminal go run hello.go Will be output :Hello, world!
go run Although the command will compile and execute the code , But it will not save the compiled program , If you want to compile the code into an executable file, you need go build 了
function go build . You can generate an executable file with the current directory name , If you want to specify a file name, you can use go build -o file name
go build Cross compiling is also supported , The target program compilation of different architectures and systems can be realized on the three mainstream operating systems .
Mac Compile below Linux, Windows Platform 64 Bit executable
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build .
Linux Compile below Mac, Windows Platform 64 Bit executable
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build .CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build .
Windows Compile below Mac, Linux Platform 64 Bit executable
SET CGO_ENABLED=0 SET GOOS=darwin3 SET GOARCH=amd64 go build .SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build .
If you want to compile arm64 The architecture of the program only needs to put the above GOARCH Set the environment variable to arm64 That's it , Is it very convenient .
Welcome to my WeChat official account. Notes on Jiangda
边栏推荐
- Wechat applet development beginner 1
- [leetcode] 20. Valid brackets
- Basic learning of SQL Server -- creating databases and tables with code
- Enumeration, simulation, and sorting
- Chisel tutorial - 03 Combinatorial logic in chisel (chisel3 cheat sheet is attached at the end)
- Kubectl 好用的命令行工具:oh-my-zsh 技巧和窍门
- Connect diodes in series to improve voltage withstand
- 企业应用需求导向开发之人力部门,员工考勤记录和实发工资业务程序案例
- webflux - webclient Connect reset by peer Error
- Archery installation test
猜你喜欢
![P1067 [noip2009 popularity group] polynomial output (difficult, pit)](/img/1f/a798879a0d65eccefa339b288f2102.jpg)
P1067 [noip2009 popularity group] polynomial output (difficult, pit)

关于CH32库函数与STM32库函数的区别

如何衡量产品是否“刚需、高频、痛点”
![[leetcode] 20. Valid brackets](/img/42/5a2c5ec6c1a7dbcdfb2226cdea6a42.png)
[leetcode] 20. Valid brackets
![Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer](/img/1f/cd38b7c6f00f2b3e85d4560181a9d2.png)
Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer

Ping error: unknown name or service

Introduction to programming hardware

Basic learning of SQL Server -- creating databases and tables with code

用语雀写文章了,功能真心强大!

平衡二叉樹【AVL樹】——插入、删除
随机推荐
用語雀寫文章了,功能真心强大!
Access database query all tables SQL
Navicat connects Oracle
保证接口数据安全的10种方案
[leetcode] 20. Valid brackets
Data analysis series 3 σ Rule / eliminate outliers according to laida criterion
MySQL Architecture
archery安装测试
C - minute number V3
数据库面试题+解析
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
Basic learning of SQL Server -- creating databases and tables with code
Pigsty:开箱即用的数据库发行版
Orthodontic precautions (continuously updated)
Is it safe to buy funds online?
Redis caching tool class, worth owning~
Chisel tutorial - 04 Control flow in chisel
解析token的网址
Alibaba cloud MySQL cannot connect