Go語言 - HelloWorld

Go語言 - HelloWorld

概念

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

  • 簡單、可靠、高效是其特點,Go語言支持併發,提供海量並行的支持。相比C++,Go語言中開啓線程十分方便。
  • 由於這些特點,Go語言是一門專門用於巨型中央服務器的語言。

安裝(Ubuntu)

  • 可以在其官網下載安裝包,也可以使用apt命令安裝。
sudo apt-get update
sudo apt-get install golang-go
  • 安裝完成後,在終端輸入go,輸出如下
linduo@lindo:~/Work$ go
Go is a tool for managing Go source code.

Usage:

	go command [arguments]

The commands are:

	build       compile packages and dependencies
	clean       remove object files
	doc         show documentation for package or symbol
	env         print Go environment information
	fix         run go tool fix on packages
	fmt         run gofmt on package sources
	generate    generate Go files by processing source
	get         download and install packages and dependencies
	install     compile and install packages and dependencies
	list        list packages
	run         compile and run Go program
	test        test packages
	tool        run specified go tool
	version     print Go version
	vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

	c           calling between Go and C
	buildmode   description of build modes
	filetype    file types
	gopath      GOPATH environment variable
	environment environment variables
	importpath  import path syntax
	packages    description of package lists
	testflag    description of testing flags
	testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

HelloWorld

  • hello.go
/* 包聲明
 * main包表示一個可獨立執行的程序
 */
package main

// 引用包,引入fmt
import "fmt"

func main() {
	// 定義變量
    var str string = "Hello World"
    // 語句
    fmt.Println(str)
}
  • 執行
go run hello.go

# 或編譯爲二進制

go build hello.go
./hello
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章