Home > Backend Development > Golang > Do you know the basic elements of go program?

Do you know the basic elements of go program?

藏色散人
Release: 2020-12-14 17:56:26
forward
9449 people have browsed it

The following column will introduce you to the basic elements of the go program from the golang tutorial column. I hope it will be helpful to friends in need!

Do you know the basic elements of go program?

1. The first non-commented line in the source file must indicate which package this file belongs to

  • For example : package main
  • Every Go application contains a package named main

2. The package name must be lowercase, and the file name must be lowercase and underlined.

  • Source files belonging to the same package must all be compiled together. A package is a unit during compilation, so according to convention, each directory only contains one package

3. When you import multiple packages, it is best to arrange the package names in alphabetical order. This will make it clearer and easier to read.

//简写
import (
"fmt"
"os"
)
// 该方法同样适用于 const、var 和 type 的声明或定义
Copy after login

4,_ Underscore
_ itself is a special identifier, called a whitespace identifier. It can be used in variable declarations or assignments like other identifiers (any type can be assigned to it), but any values ​​assigned to this identifier will be discarded, so these values ​​cannot be used in subsequent code, nor This identifier cannot be used as a variable to perform assignments or operations on other variables.

5. A source file can contain any number of lines of code. Go itself has no limit on the size of the source file.

  • The code of the program is structured through statements. Each statement does not need to end with a semicolon ; like other languages ​​in the C family, because this work will be done automatically by the Go compiler.
  • If you plan to write multiple statements on the same line, they must be artificially distinguished by (;), but in actual development we do not encourage this practice.

The above is the detailed content of Do you know the basic elements of go program?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template