Home>Article>Backend Development> What is the go language package?

What is the go language package?

藏色散人
藏色散人 Original
2020-12-18 14:56:00 3545browse

Go language package is the basic management unit of golang. There can be multiple different files in the same package. As long as the header of each file has the same name of "package xxx", it can be used in the main method Use "xxx.Method()" to call methods in different files.

What is the go language package?

The operating environment of this tutorial: Windows 7 system, GO version 1.18, Dell G3 computer.

Understanding of go package

golang package is the basic management unit. Under the same package, there can be many different files, as long as the header of each file If they all have the same name such as "package xxx", you can use xxx.Method() in the main method to call methods in different files.

The folder name can be inconsistent with the name of the package.

For example, I have a folder named mypackage, which contains three files: a.go, b.go, and c.go:

mypackage | --a.go | --b.go | --c.go

For example, there is Saya() in a.go, and Sayb() in b.go. The package name common to several files is indeed testpackage

, so call a in the main function. Just use the respective methods in go and b.go files, testpackage.Saya(), testpackage.Sayb().

There is also the default init method, which is executed when the import comes in, and each file is allowed to have the init() method. Of course, each one will be executed.

Related introduction:

Go (also known as Golang) is a statically strongly typed, compiled, concurrent, and garbage collection programming language developed by Google.

Robert Griesemer, Rob Pike and Ken Thompson began designing Go in September 2007, and later Ian Lance Taylor, Russ Cox joins the project. Go is developed based on the Inferno operating system. Go was officially announced in November 2009, becoming an open source project and implemented on Linux and Mac OS X platforms, and later added implementation under Windows systems. In 2016, Go was selected as "TIOBE's Best Language of 2016" by the software evaluation company TIOBE. Currently, Go releases a second-level version every six months (that is, upgrading from a.x to a.y).

For more related technical articles, please visit thego languagecolumn!

The above is the detailed content of What is the go language package?. 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