当前位置:网站首页>[go basics 02] the first procedure
[go basics 02] the first procedure
2022-07-25 21:59:00 【Fighting_ hawk】
Catalog
1 General idea
- Conceive the storage structure of all your programs , Design the catalogue .
- According to the purpose of the procedure , Edit code .
- debugging .
- compile .
- function .
2 New project and project file structure
- Create a new folder on the appropriate hard disk , File used to store new projects , In this paper D New folder under disk “GOProject”, It is suggested that the folder be named in English , I don't know if there will be problems with the Chinese path .
- double-click goland, Click on new project New projects .

- Choose the appropriate storage path for the project , It is the folder created in step 1 , At the same time pay attention to GOROOT Is it SDK Installation path for .

- Create the folder where the first program is located . Right click GOProject, Click on NEW, You can create new files or folders ,GO File Means to create a new go file ,directory Means to create a new folder .

- The same way , stay “01helloWorld” Create two subfolders under the folder , Respectively main and package, The former is used to store the main execution code , The latter is used to store various modules . stay main In the folder , establish go Program , Name it helloWorld, The file structure is as follows .

2 Program code
- Procedural requirements : Output hello world!
- The code and explanation are as follows :
// Each program belongs to a package
package main
// Introduce modules
import "fmt"
// The main function , As program entry
func main() {
fmt.Println("hello world!")
}
3 Compile and run
3.1 Execute the process
- Prepared go A program can have two execution processes , One is to compile it into an executable file before running , One is direct operation ( Commonly used for debugging ).
- difference :
(1) If you compile the executable file first , Then you can copy the executable file to no go Running on the machine of the development environment ;
(2) If it's direct go run Source code , So if you want to run on a machine like this , It also needs go development environment , Otherwise, it cannot run ;
(3) At compile time , The compiler will include the library files that the program depends on in the executable file , therefore , The executable file is much larger .
3.2 compile
- The basic method : open go The folder where the source file is located , Address field input cmd Open the terminal , Input
go build+go The source file name, The program can be compiled into an executable file with the same name .
- Custom generated file name : Input
go build -o myname.exe go The source file name, The program can be compiled into an executable file with the same name . - utilize goland compiling : Right click the code area and select run , Or use the shortcut key ctrl+shift+F10, Compile , The effect is the same as the basic method .

3.3 debugging
- utilize goland Debug the code line by line , First, add a line of command output to the program hello, Then hit the left mouse button on the left side of the same line to mark the breakpoint .

- Right click the code area , Click on debug, You can pause the program at the breakpoint , You can press F7、F8 And other shortcut keys use different line by line debugging methods .

3.4 function
- The basic method : Double click directly to run ( Because the pause command is not set , After the program runs, it closes directly ).
- cmd Window run executable : Under the path of the executable program , Enter the executable program name , Direct operation .

- cmd Window run source file : Under the path of the source file , Enter the command
go run The source file nameRun the source program directly .
4 summary
- Write the first go Program .
- understand goland In the new project 、 Organize the project file structure 、 edit 、 debugging 、 Compilation and other aspects of the use of .
reference
- 《Go Program development and basic structure description 》 Video tutorial
- 《Go Perform process analysis 》 Video tutorial
- 《Go Compile and run 》 Video tutorial
边栏推荐
- The reisson distributed lock renewal failed due to network reasons, resulting in the automatic release of the lock when the business is still executing but the lock is not renewed.
- sql语句练习题整理
- New maixhub deployment (v831 and k210)
- 若依如何解决导出使用下载插件出现异常?
- [dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)
- ZigBee development board (nxpzigbee Development)
- JS timer and swiper plug-in
- 虚拟内存与磁盘
- 在腾讯干软件测试3年,7月无情被辞,想给划水的兄弟提个醒...
- 【Redis底层解析】链表类型
猜你喜欢

Bitcoin.com:USDD代表了真正去中心化稳定币

Shopify sellers: share some tips for social media marketing!

别投了,软件测试岗位饱和了...

Basic knowledge in the project

自动化测试岗花20K招人,到最后居然没一个合适的,招两个应届生都比他们强吧

虚拟内存与磁盘

JMeter websocket接口测试

『SignalR』.NET使用 SignalR 进行实时通信初体验

How to implement distributed locks with redis?
![[MAIXPY]kpu: load error:2005, ERR_ READ_ File: read file failed problem solving](/img/0b/da67b5a361a2cdfaf81568d34cf5f7.png)
[MAIXPY]kpu: load error:2005, ERR_ READ_ File: read file failed problem solving
随机推荐
Web3 entrepreneurship has all the elements of explosive growth of innovation
Bitcoin.com:USDD代表了真正去中心化稳定币
Redis usage details
Solutions to the failure of win key in ikbc keyboard
golang : MVC之models
c sqlite ... ...
[dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)
Animation curves are used every day. Can you make one by yourself? After reading this article, you will!
成为比开发硬气的测试人,我都经历了什么?
关于接口测试你想知道的都在这儿了
如何快速搭建图片服务器[通俗易懂]
I/O案例实操
The file cannot be saved (what if the folder is damaged and cannot be read)
[51nod1676 undirected graph isomorphism] undirected graph hash [easy to understand]
Golang: MVC models
Acwing 866. determining prime numbers by trial division
Children's programming electronic society graphical programming level examination scratch level 1 real problem analysis (judgment question) June 2022
卸载npm和安装npm_使用`npm uninstall`卸载npm软件包「建议收藏」
少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年6月
Special class design