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

How to introduce packages in go language

王林
王林Original
2021-01-07 16:33:344961browse

How to introduce packages in Go language: You can directly use [import "package name"] to introduce a package. If you need to import multiple packages at the same time, you can use [import {"package name" "package name" "package name"}] to import them.

How to introduce packages in go language

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

(Learning video sharing: Programming teaching)

Specific method:

The first is the simplest way to import packages, which is to use import directly "fmt" to import an fmt package

How to introduce packages in go language

If you want to import multiple packages at the same time, you can write like this

How to introduce packages in go language

Of course, you can also use the following method for importing multiple packages. However, the following writing format will be automatically formatted in the second way when gofmt is used.

How to introduce packages in go language

The most commonly used way of writing imported package modules is as follows

How to introduce packages in go language

Sometimes the package we import is in the secondary directory, then you can write like this

import "net/http" imports the http module in the net directory

How to introduce packages in go language

Of course, GO language supports direct import of an online module. For example, the third-party package module is on github; we can directly use import "url" to import it without downloading and installing it

How to introduce packages in go language

In fact, the functional principle of online importing package module is as follows . The GO compiler will automatically download the package file in the URL to the local GOPATH directory you set. The directory format is the directory path of the URL, and then perform the import operation. We can combine the above import methods, as shown below

How to introduce packages in go language

Related recommendations:golang tutorial

The above is the detailed content of How to introduce 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