1024programmer Java Quickly start the go program (2)

Quickly start the go program (2)

The Go language provides a complete standard library, which provides all the core libraries needed to build actual Web-based and network-based programs.
1.go program architecture
Search for data in all different data sources.
2.1 Illustration 1
This program is divided into Multiple different steps, running in multiple different goroutines. Starting from the main goroutine, going to the goroutine that performs the search and the goroutine that tracks the results, and finally returns to the main goroutine. The structure of the entire project:

2 .Program entrance main.go

package main

 import (
 _ "github.com/goinaction/code/chapter2/sample/matchers"

 // init is called before main
 func init() {
 // Output logs to standard output

 // main is the entry point of the entire program
 func main() {
 // Search using specific items

2.1 Two characteristics of Go program:
The first characteristic is the declared function named main. When building an executable file, you need to find this declared main function
and use it as the entry point of the program. The second feature is that there is a main package. The main function is saved in a package named main, otherwise the executable file will not be generated.
2.2 Each code file in the Go language belongs to a package. A package defines a set of compiled codes. The name of the package is similar to a namespace
and can be used to indirectly access identifiers declared in the package. This feature can distinguish identifiers with the same name defined in different packages. ​​
​ 2.3 The keyword import is to import a piece of code so that users can access its identifiers, such as types, functions, constants and interfaces.
2.4 Readers may notice that when importing the matchers package, there is an underscore in front of the imported path. The code is as follows:
_ “github.com/goinaction/code/chapter2/sample/matchers”
This technology is to allow the Go language to initialize the package, but does not use the identifier in the package.
2.5 The init function in each code file in the program will be called before the main function is executed.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/764988

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top