In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the content of the sample analysis of Golang. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Brief introduction of Go language
Go was developed by Robert Griesemer, Rob Pike and Ken Thompson in late 2007, and later joined Ian Lance Taylor, Russ Cox and others. Finally, it was open source in November 2009 and released a stable version of Go 1 in early 2012.
Go language (referred to as Golang) is the C language in the era of cloud computing. The birth of Go enables programmers to have higher production efficiency. Go language is specially optimized for multiprocessor system application programming. Programs compiled with Go can be as fast as C or C++ code. It is also more secure and supports parallel processes.
Go language is to build a bridge between python and CCompact +, providing a fast execution speed, rapid development, making it a high-performance language, but also making development faster.
Advantages of Go language
Can be directly compiled into machine code, do not rely on other libraries, the version of glibc has requirements, simple deployment (directly put a file).
Statically typed language, but feels like a dynamic language.
Statically typed languages: most hidden problems can be detected at compile time
Dynamically typed languages: many packages can be used directly, making it efficient to write code.
At the language level, supporting development is also a feature of the Go language, so that Go can directly make full use of multicore and can easily use concurrency, which is one of the reasons why many companies use Go as a background server.
Built-in Runtime, which supports garbage collection, is one of the features of dynamic languages. GC (garbage collection mechanism) for earlier versions of Go is not perfect, but it is sufficient for most situations.
Easy to learn, the author of the Go language has a C foundation. So many parts inherit the content of C, including the features of most languages: inheritance, overloading, objects, and so on.
Rich standard library, Go language currently has a large number of built-in libraries, especially the network library.
Built-in powerful tools, Go language built-in many tool chains, such as gofint tools, automated formatting code.
Cross-platform compilation
Embedded C support, Go can also directly contain C code, using the existing rich C library.
Suitable use of Go language
Server programming (dealing with logs, data packaging, virtual machine processing, file systems, etc.), compared to before Go, C or C++ is doing similar things.
Distributed system, database agent, etc.
Network programming (the most widely used area): including Web applications, API applications, download applications.
In-memory database: such as part of groupcache and couchbase developed by Google.
Cloud platform
Environment building
Since I have a MAC system, as far as Fusion is concerned, only the Ubuntu system is installed, so for the learning partner in the windows installation environment, you can Google Search directly.
Installation in MAC OS environment using brew
Brew install go or brew install golang
Directly on the command line in the Ubuntu system environment:
Apt install golang-go
After the installation is complete, you can use go version directly to see if the go installation was successful and to view its version.
After setting up the environment of Go, it is the choice of compiler. I particularly like Goland in the JetBrains family. You can Google Search the specific installation.
Overview of standard command
For an overview of standard commands, please refer to: https://studygolang.com/pkgdoc
The first Go language
The basic components of the Go language are as follows:
Package declaration
Introduction packet
Function / function body
Variable
Statement & expression
Annotation
Package main / / package main defines the package name. The first uncommented line in the source file must indicate which package import ("fmt") / * import "fmt" the file belongs to. Tell the Go compiler that the program needs to use the fmt package (functions, or other elements), which implements the function to format IO (input / output). * / func main () {/ / func main () is the function that the program starts to execute (the entry of the function). The main function must be included in every executable program, and it is generally the first function to execute after startup (if there is an init () function, it will be executed first). / * this is the hello world program * / *. * / is a comment and will be ignored when the program is executed. Single-line comments are the most common form of comments, and you can use single-line comments that start with / / anywhere. Multiline comments, also known as block comments, all begin with / * and end with * /, and cannot be used nested. Multiline comments are commonly used for documentation of packages or code snippets that are commented into blocks. Fmt.Println ("Hello,Go World!") / / fmt.Println (...) You can output the string to the console and automatically add newline characters\ n at the end. Print and Println functions also support the use of variables}
With regard to the package, the following points are drawn from the local test:
There is no direct relationship between the file name and the package name, and it is not necessary to make the file name the same as the package name.
The folder name is not directly related to the package name and does not need to be consistent.
Files in the same folder can only have one package name, otherwise an error will be reported in the compilation.
Thank you for reading! This is the end of this article on "sample Analysis of Golang". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.