"Go to learn One" Hello world

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Recent projects need to be developed 抗并发的db proxy,API GATEWAY and so on, along with various problems in the process of virtualization. As an old programmer, the Go language learning is urgent.

First, the basic background

Go is a programming language developed by Google 静态强类型、编译型、并发型 , and 具有垃圾回收 features

For the features of the Go language, the online Daniel Summary, for the individual special value 语言交互和并发性 :

    • Automatic garbage collection
    • Richer built-in types
    • function multiple return value
    • Error handling
    • Anonymous functions and closures
    • Types and Interfaces
    • Concurrent programming
    • Reflection
    • Language interactivity

Second, installation

Suggested References:
Http://dmdgeeker.com/goBook/d ...

It is important to note that Gopath must be configured, configured to its own workspace:

# go path change by cuihuanexport GOPATH=/Users/cuixiaohuan/Desktop/workspace/goexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOPATH

Workspace's Basic directory specification can be consulted: https://go-zh.org/doc/code.html

    • The SRC directory contains the source files for go, which are organized into packages (each directory corresponds to a package).
    • The PKG directory contains the package object,
    • The bin directory contains executable commands.

Third, Hello World

Code

package mainimport "fmt"func main() {   fmt.Println("Hello World")}

Language Description:
1:package is required, for standalone run executable files, must be package main
2:import represents the introduced package, or the library
3: Main function in the program
4: Execute function

Run:

cuixiaozhuai:main cuixiaohuan$ go build hello.gocuixiaozhuai:main cuixiaohuan$ ./helloHello World

Compile and run are very simple, and more convenient is the cross-platform compilation

# mac 下编译cuixiaozhuai:main cuixiaohuan$ env GOOS=linux GOARCH=amd64 GOARM=7 go build hello.go # linux 开发机运行[work@xx.com ~]$ ./helloHello World

"Reprint Please specify:" Go learning One "Hello World | "A very small and reliable"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.