日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

go语言实现第一个程序-hello,world!

發(fā)布時(shí)間:2025/3/21 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 go语言实现第一个程序-hello,world! 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

0.前言
工作中一直使用c++編寫(xiě)高并發(fā)服務(wù)器程序,但c++編寫(xiě)高并非服務(wù)器程序時(shí)多線程邏輯,鎖機(jī)制導(dǎo)致的死鎖,內(nèi)存泄漏,崩潰等問(wèn)題會(huì)耗費(fèi)大量時(shí)間和精力。

聽(tīng)同事說(shuō)go語(yǔ)言是專門(mén)做高并發(fā)編程的,不用考慮上面的一些問(wèn)題,由google推出。想想google出品,必屬精品,又和自己的工作方向相關(guān),所以了解一下。


1.編譯工具安裝

使用源碼安裝或者命令安裝都可以,ubuntu下使用命令安裝:

$ sudo apt-get install golang
安裝完成后,看看版本號(hào):

$ go version go version go1.6.2 linux/amd64 在shell終端輸入go命令看看用法:

$ go Go is a tool for managing Go source code.Usage:go command [arguments]The commands are:build compile packages and dependenciesclean remove object filesdoc show documentation for package or symbolenv print Go environment informationfix run go tool fix on packagesfmt run gofmt on package sourcesgenerate generate Go files by processing sourceget download and install packages and dependenciesinstall compile and install packages and dependencieslist list packagesrun compile and run Go programtest test packagestool run specified go toolversion print Go versionvet run go tool vet on packagesUse "go help [command]" for more information about a command.Additional help topics:c calling between Go and Cbuildmode description of build modesfiletype file typesgopath GOPATH environment variableenvironment environment variablesimportpath import path syntaxpackages description of package liststestflag description of testing flagstestfunc description of testing functionsUse "go help [topic]" for more information about that topic.

里面常用的就是build和run命令了。

2.編譯運(yùn)行命令

go語(yǔ)言的源碼后綴名為.go,寫(xiě)一個(gè)main.go的hello world程序:

// main.go package mainimport "fmt"func main() {fmt.Println("Hello, World!") }
注釋支持c++的注釋方式,需要注意的一點(diǎn)就是函數(shù)的大括號(hào)必須放在后面,否則編譯不通過(guò)。

編譯命令:

go build -o main main.go編譯后就生成了執(zhí)行程序main,在終端下./main可以直接運(yùn)行了
編譯運(yùn)行命令:

$ go run main.go Hello, World!
3.文檔以及參考資料

go語(yǔ)言教程 | 菜鳥(niǎo)教程

go語(yǔ)言中文社區(qū)

總結(jié)

以上是生活随笔為你收集整理的go语言实现第一个程序-hello,world!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。