This article is a mirror article of machine translation, please click here to jump to the original article.

View: 7591|Reply: 0

Windows Golang Getting Started Tutorial

[Copy link]
Posted on 9/16/2019 4:02:26 PM | | | |
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)




Previous:Golang in String and Int types are converted to each other
Next:Ask for the hook of C language 64 bits
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com