Home  >  Article  >  Backend Development  >  How to import packages in go language

How to import packages in go language

王林
王林Original
2021-02-04 11:44:213326browse

How to import packages in Go language: You can import packages through import statements, such as [import "Package 1"] or [import ("Package 1" "Package 2")]. There are two basic formats for import, namely single-line import and multi-line import. The import code effects of the two import methods are the same.

How to import packages in go language

The operating environment of this article: windows10 system, Go 1.11.2, thinkpad t480 computer.

You can include zero to more import package declaration statements after a Go language source file package declaration statement and before other non-import declaration statements. Each import statement can specify an import path individually, or multiple import paths can be imported simultaneously through parentheses. To reference identifiers of other packages, you can use the import keyword. The imported package name is surrounded by double quotes. The package name is the path calculated starting from GOPATH and is separated by /.

Default import writing method

There are two basic formats for import, namely single-line import and multi-line import. The import code effect of the two import methods is the same.

1. Single-line import

The format of single-line import is as follows:

import "包1"
import "包2"

2. Multi-line import

When importing in multiple lines, the package name is in the import The order does not affect the import effect, the format is as follows:

import(
    "包1"
    "包2"
    …
)

Related recommendations: golang tutorial

The above is the detailed content of How to import packages in go language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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

Related articles

See more