当前位置:网站首页>学go之路(一)go的基本介绍到第一个helloworld
学go之路(一)go的基本介绍到第一个helloworld
2022-07-06 07:15:00 【虎起来】
1.go安装与环境变量配置:
进入https://golang.google.cn/dl/
选择go的版本及系统进行安装
安装完后设置GOHOME,并将GOHOME/bin加入到环境变量中
完成后输入go验证是否安装成功
2.go的优点:
1.自带gc。
2.静态编译,编译好后,扔服务器直接运行。
3.简单的思想,没有继承,多态,类等。
4.丰富的库和详细的开发文档。
5.语法层支持并发,和拥有同步并发的channel类型,使并发开发变得非常方便。
6 简洁的语法,提高开发效率,同时提高代码的阅读性和可维护性。
7.超级简单的交叉编译,仅需更改环境变量。
3.go的特征:
1.自动立即回收。
2.更丰富的内置类型。
3.函数多返回值。
4.错误处理。
5.匿名函数和闭包。
6.类型和接口。
7.并发编程。
8.反射。
9.语言交互性
4.go文件名
所有的go源码都是以 “.go” 结尾。
5.go的语言命名:
1.Go的函数、变量、常量、自定义类型、包(package)的命名方式遵循以下规则:
1)首字符可以是任意的Unicode字符或者下划线
2)剩余字符可以是Unicode字符、下划线、数字
3)字符长度不限
2.Go只有25个关键字
break default func interface select case
defer go map struct chan else
goto package switch const fallthrough if
range type continue for import return
var
3.Go还有37个保留字
Constants: true false iota nil Types: int int8 int16 int32
int64
uint uint8 uint16 uint32 uint64 uintptr
float32 float64 complex128 complex64
bool byte rune string error Functions: make len cap new append copy close delete
complex real imag
panic recover
4.可见性:
1)声明在函数内部,是函数的本地值,类似private
2)声明在函数外部,是对当前包可见(包内所有.go文件都可见)的全局值,类似protect
3)声明在函数外部且首字母大写是所有包可见的全局值,类似public
6.Go语言声明:
有四种主要声明方式:
var(声明变量), const(声明常量), type(声明类型) ,func(声明函数)
Go的程序是保存在多个.go文件中,文件的第一行就是package XXX声明,用来说明该文件属于哪个包(package),package声明下来就是import声明,再下来是类型,变量,常量,函数的声明。
7.Go项目构建及编译
一个Go工程中主要包含以下三个目录:
src:源代码文件
pkg:包文件
bin:相关bin文件
8.Go的第一个helloworld
新建goproject
goproject下新建src、pkg、bin
打开src新建helloworld.go,并输入以下内容
package main
import "fmt"
func main(){
fmt.Println("hello world")
}
命令行窗口执行go build
生成一个helloworld的exe文件
执行该文件即可以打印出hello world
边栏推荐
- Leetcode 78: subset
- #systemverilog# 可綜合模型的結構總結
- The difference between get and post request types
- Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
- leetcode1020. Number of enclaves (medium)
- The author is dead? AI is conquering mankind with art
- OpenGL ES 学习初识(1)
- Embed UE4 program into QT interface display
- Idea console color log
- Misc of BUU (update from time to time)
猜你喜欢
Lesson 12 study notes 2022.02.11
杰理之AD 系列 MIDI 功能说明【篇】
Top test sharing: if you want to change careers, you must consider these issues clearly!
微信公众号无限回调授权系统源码 全网首发
ORACLE列转行--某字段按指定分隔符转多行
mysql如何合并数据
呆错图床系统源码图片CDN加速与破解防盗链功能
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
[daily question] 729 My schedule I
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
Interface automation test framework: pytest+allure+excel
[some special grammars about C]
OpenJudge NOI 2.1 1749:数字方格
软件测试外包到底要不要去?三年真实外包感受告诉你
TS基础篇
数字IC设计笔试题汇总(一)
Simple and understandable high-precision addition in C language
Top test sharing: if you want to change careers, you must consider these issues clearly!
Applied stochastic process 01: basic concepts of stochastic process
MVVM of WPF
Embed UE4 program into QT interface display
The psychological process from autojs to ice fox intelligent assistance
【mysql学习笔记30】锁(非教程)
【mysql学习笔记29】触发器
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
supervisor 使用文档
Zhongqing reading news
leetcode841. Keys and rooms (medium)
First knowledge of OpenGL es learning (1)
You deserve this high-value open-source third-party Netease cloud music player