Go Program structure Go Go

Source: Internet
Author: User
Tags aliases

General structure of Go program:

    • Go programs are organized through the package (similar to Python)
    • Only packages with a package name called Main can contain the main function
    • One executable program has and only one Mian package
    • Importing Other non-main packages with the Import keyword
    • Constants are defined by the const keyword
    • Declaring and assigning global variables by using the var keyword outside the body of the function
    • Declaration of a struct (struct) or interface (interface) using the type keyword
    • Declaring a function with the func keyword

Basic components of the Go language

    • Package Declaration
    • Introduction Package
    • Function
    • Variable
    • Statements & Expressions
    • Comments

Format of Go Import package

--After importing the package, you can use the format <PackageName>.<FuncName> to call the functions in the package;

--If a function or type that is not called after the package is imported will report a compilation error

Package aliases

-When a third-party package is used, the package name may be very close or identical, and the alias can be used to differentiate and invoke

Omit call

- not recommended to use , easy to confuse

- cannot be used with aliases at the same time

Visibility stocks

In the-go language, the case is used to determine whether the constant, variable, type, interface, struct, or function can be called by an external package.

By convention, the first letter of the function name is private, and the first letter of The function name is public

192 Reads
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.