Home  >  Article  >  Backend Development  >  How to import packages in golang

How to import packages in golang

silencement
silencementOriginal
2019-12-25 11:52:132478browse

How to import packages in golang

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 at the same time through parentheses. To reference identifiers of other packages, you can use the import keyword. The imported package name is enclosed in 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 effect of the import code of the two import methods is the same.

1) Single-line import

The single-line import format is as follows:

import "包1"
import "包2"

2) Multi-line import

When importing 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"
    …
)

It is recommended to study "golang tutorial".

The above is the detailed content of How to import packages in golang. 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