How do I start go programming?

Source: Internet
Author: User
Tags custom name

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

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 Catalog

Cgo_enabled: Whether to enable CGO

Cc

CXX

Gogccflags

Gorace: Data sync detection, with Go test, go run, go build, go install-race option.

Gopath:go Package Lookup Path

2. Code organization:

-$GOPATH contains multiple workspace

-Workspace contains src, pkg, bin

-SRC contains the package, which is program, library

-Package contains go file

Need to understand:

* Package name vs Package path

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

Package Import Complete Syntax:

Import [Name] "path"

which

The name section can

  1. None, use the default name of the package declaration
  2. Points, using the current package
  3. Blank, execute init only
  4. Name, custom name

The path section can

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

Note: You cannot use the vendor mechanism to have a relative path, otherwise the parsing error occurs.

* Program vs Library

Package name for main means program

Package name non-main means library

3. Code Testing

Execute the test code using the Go Test command.

      • The test file is suffixed with _test.
      • Test func is prefixed with test.

4. Remote Package

Use the go get command to get the remote package.

But the Go Test command relies on git or svn.

How do I start go programming?

Related Article

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.