当前位置:网站首页>【Go基础】1 - Go Go Go
【Go基础】1 - Go Go Go
2022-07-04 07:40:00 【李易安QSR】
一、Go历史
1、起源
诞生于谷歌,为了解决以下问题
- 多核硬件架构
- 超大规模分布式计算集群
- Web模式导致的前所未有的开发规模和更新速度
2、Go语言创始人

3、为什么叫Go

名字足够简单,不管作为后缀,还是加一些工具类型
4、安装和下载
官网啥都有:https://golang.google.cn/
IDE:Atom、VSCode、GoLand
二、Go的第一行代码
1、开发环境构建
- 1.8版本之前必须要设置GOPATH这个环境变量
- 1.8版本之后如果没有设置环境变量,会使用默认值
- Unix上会默认$HOME/go
- windows上会默认是%USERPROFILE%/go
- 在Mac上GOPATH可以通过修改用户级别环境变量,~/.bash_profile来进行设置
如何查看自己的go版本
go version
如何查看自己当前环境变量配置
go env
2、记事本编写hello.go
package main //包,表明代码所在的模块
//引入标准化输入输出包
import "fmt"
func main() {
fmt.Println("hello go!")
}
执行命令
# 直接运行
go run hello.go
# 直接生成二进制(可执行文件,windows会直接生成一个.exe文件)
go build hello.go
3、Go如何识别应用程序入口
三点必须
- 必须是main包下边(文件夹名字和package名字一般情况下需要一样,go不做强制要求)
问:如何定义这个main包呢?创建一个名字是main的文件夹就可以?
答:不是的,只是需要在这个文件的第一行,声明package时候说明为main
- 必须是main方法
- 文件名不一定是main.go(但是习惯上是)
4、如何控制台传参
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println(os.Args)
if len(os.Args) > 1{
fmt.Println("***" + os.Args[1])
}
os.Exit(0)
}
5、如何编写一个测试程序
需要满足
- 文件名以“_test”结尾
- 方法名以“Test”开头
边栏推荐
- Flask 常用组件
- zabbix监控系统自定义监控内容
- MYCAT middleware installation and use
- 2022-021ARTS:下半年开始
- It's healthy to drink medicinal wine like this. Are you drinking it right
- Rapidjson reading and writing JSON files
- How to use MOS tube to realize the anti reverse connection circuit of power supply
- Is l1-029 too fat (5 points)
- 论文学习——基于极值点特征的时间序列相似性查询方法
- Electronic Association C language level 1 34, piecewise function
猜你喜欢

L1-027 rental (20 points)

zabbix監控系統自定義監控內容
![[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)](/img/5c/afb0d43665a8b46579dc604d983790.jpg)
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)

SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)

socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa

论文学习——基于极值点特征的时间序列相似性查询方法

This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears

【Kubernetes系列】Kubernetes 上安装 KubeSphere

The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native

线性代数1.1
随机推荐
Electronic Association C language level 1 34, piecewise function
JVM中堆概念
MySQL error resolution - error 1261 (01000): row 1 doesn't contain data for all columns
墨者学院-phpMyAdmin后台文件包含分析溯源
Activiti常见操作数据表关系
Blue Bridge Cup Quick sort (code completion)
Relations courantes de la fiche de données d'exploitation pour les activités
zabbix监控系统自定义监控内容
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
BUUCTF(4)
如何用MOS管来实现电源防反接电路
Application of isnull in database query
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Is l1-029 too fat (5 points)
Jianmu continuous integration platform v2.2.2 release
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
Literature collation and thesis reading methods
两年前美国芯片扭捏着不卖芯片,如今芯片堆积如山祈求中国帮忙
Implementation of ZABBIX agent active mode