Go is a new language, a concurrent, garbage collection, fast-compiling language.
- It can compile a large Go program on a computer in a matter of seconds.
- Go provides a model for software construction that makes dependency analysis easier and avoids the beginning of most C-style include files and libraries.
- Go is a statically typed language, and its type system has no hierarchy. So users don't need to spend time defining relationships between types, which feels lighter than typical object-oriented languages.
- Go is a completely garbage collection language and provides basic support for concurrent execution and communication.
- By its design, Go intends to provide a way to construct system software on multi-core machines.
Download and install
The hyperlink login is visible.Click the "Microsoft Windows" platform link to download and install it all the way to next, as shown in the figure below:
Check the version
After the installation is completed, you can run the View Version command in the cmd window to test whether the installation is successful, as shown in the following figure:
Hello word program
Regardless of which development language you are getting started with, in the first example, it is usually the console that outputs the hello word string.
The code is as follows:
Go run compiles and runs the Go program
Hello Golang, My name is itsvse, I am 5 years old.
Go has two reserved functions: the init function (which can be applied to all packages) and the main function (Can only be applied to package main)。 These two functions cannot have any parameters and return values when defined. Although you can write as many init functions as you want in a package, we strongly recommend that you write only one init function per file in a package, both for readability and later maintainability.
Go programs automatically call init() and main(), so you don't need to call these two functions anywhere. The init function in each package is optional, butpackage main must contain a main function。
go build compile code
If you have multiple files in a project folder and you only want to compile a certain file, you can add a file name after go build, e.g. go build a.go; the go build command will compile all go files in the current directory by default.
If it is the main package, when you execute go build, it will generate an executable file in the current directory.
The compiled executable file size is close to 2m.
Enable the HTTP service
If you develop an HTTP service in Golang, you can use the functions provided by the net/http package. The net/http package provides a very complete set of functions, and the HTTP service launched is also very stable and efficient, and can be used in a production environment.
Code:
Then access it in the browser http://localhost:9090 and you can see the Hello golang http! output.
(End)
|