The go language introduces a standard model for error handling, the error interface, which is defined as follows:
Type Error Interface {
Error () string
}
For most functions, if you want to return an error, you can generally define it as the
This article explains how to implement a thread pool with code. Code and comments are as follows: 123456789101112131415161718192021st22232425262728293031323334353637Package Main Import "FMT"Import "Time" This is the worker thread that handles the
There are always bugs in the program development process, so the location and analysis of Bugs is critical.Golang defines a lot of error, but sometimes it is difficult to locate the problem with error, so we still need the stack information.We
1, GO environment preparation
①, download go installation package, website: https://www.golangtc.com/download (Baidu Cloud Disk: Link: Https://pan.baidu.com/s/1-js-fHcksSsBlAfa0lUOsQ Password: qn23), my Baidu cloud disk inside has 1.9.2 and 1.10.22
The
http.FileServer method belongs to the standard library
net/http and returns an HTTP processor that uses the FileSystem interface root to provide file access services. A static file server can be implemented conveniently.
In the go language, the bottom string is stored in a byte array and cannot be changed.
For example, the s:="Go编程" fmt.Println(len(s)) output should be 8 because the Chinese characters are stored in 3 bytes.
len(string(rune('编')))The result is 3.
Golang package Import and other languages there are a lot of different places, the following is a custom import
Golang Custom Import Instructions
An official note.
Relatively simple, it is not translated, mainly that we can add meta
Eight o ' clock in the morning, on the subway to work, I habitually open the work to view. A stranger asked to add me as a friend, out of a headhunter's intuition (another job seeker), and I immediately passed his request. He sent a message as soon
Package main//non-comment area a line to introduce a packet, the name of this package must be Mainimport "FMT" import "unsafe" func main () {//This is my first go program FMT. Println ("This is my first Go programma"); MYFUNC1 ()//variable//MYFUNC2
Introduced
With tutorials, you can learn and practice building your own web framework using Golang.For REST API Development learning is more helpful.
Martini has quickly become the most popular Golang web framework since its release, but it is not
-I don't use keywords
I don't have to Goto.Goto makes code execution logic difficult to read and understand.You can also use label tags to organize your codefunc main() {outer: for { log.Println("outer") for {
Reprint to: https://studygolang.com/articles/9072
In any language, dependency management is a more complex issue. The dependency management mechanism in the go language is still a bit disappointing. Before the 1.6 version, the official only put the
Time is fast, the blink of an eye to Shanghai has been four years ~
Job
The company turned the technology stack, began to move from PHP to Java, is also a chance to learn Java, compared to PHP, Java is really very cumbersome to write, but who let
Here is a special example:
package mainimport "fmt"type wenbin struct { name string number int}type wenbinstruct struct { *wenbin}func(wb *wenbin) testFunc(){ fmt.Println("wenbintestjklsd")}func main(){ fmt.Println("wenbin")
Background
Line of business activities, each new activity is to do independent project development, there is a lot of duplication of code, and waste Data Services connection resources; Sort service may want to add business code frequently, is
There are two core features in the Go language HTTP package: Conn,servemux.
Conn's GoroutineBefore we said that the user every request Conn is in a new goroutine to deal with, do not affect each other, will not be blocked, this is the high
Redis uses the process of querying a certain type of key number of problems, the simpler way to operate through the REDIS-CLI combined with keys, because the work mechanism of keys is generally disabled on the line, the following shell script
Code Warehouse Address
First, IntroductionProtobuf is a platform-independent, language-independent, extensible serialized structured data format from Google. So
it is suitable for the data exchange format which is used for data storage and
Golang's FMT package implements formatted I/O functions, similar to the C printf and scanf.
# 定义示例类型和变量type Human struct { Name string}var people = Human{Name:"zhangsan"}
Common placeholder
占位符 说明 举例
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service