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

How to import packages in golang

silencement
Release: 2019-12-25 11:52:13
Original
2558 people have browsed it

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"
Copy after login

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"
    …
)
Copy after login

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!

Related labels:
source:php.cn
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