Learning Go Programming Essentials Summary _golang

Source: Internet
Author: User

If you want to start learning go grammar, please memorize the following 4 points:

1. Environment variables:

Use Go env to view environment variables

Goarch/gohostarch: Architecture, AMD64 or 386

Goos/gohostos: Operating system, Linux or Windows

Goroot:go installation directory

Gobin:go Program Directory

Gotooldir:go Tools Directory

Cgo_enabled: Enable CGO

Cc

CXX

Gogccflags

Gorace: Data sync detection, with go to test, go run, go builds, go install-race options.

Gopath:go Package Lookup Path

2. Code organization:

-$GOPATH contains multiple workspace

-Workspace contains src, pkg, bin

-SRC contains package, program, library

-Package contains go file

Need to understand:

* Package name vs Package path

Package name refers to the Identifie that uses the package declaration in go file. Package path refers to the relative gopath paths. Same package path, same package name.

Package Import Complete Syntax:

Import [Name] "path"

which

The name section can

No, default name with package declaration
Point, using the current package
Blank, execute init only
Name, custom names
The path section can

Absolute path: A relative $gopath path
Relative path: The path relative to the current file.

Note: You cannot use the vendor mechanism to show a relative path, otherwise parsing is an error .

* Program vs Library

Package name is main representing program

Package name not main represents library

3. Code Testing

Use the Go Test command to execute the test code.

Test file has a suffix of _test.
Test func is prefixed with test.

4. Remote Package

Obtain a remote package using the go to command.

But the Go Test command relies on git or svn.

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.