Golang Language Introduction and InstallationThe go language is the open-source programming language that Google released in 2009, which uses go to compile programs that are comparable to C or C + + code, and are more secure and support parallel processes.This tutorial explains the development environment for installing the Go language on WindowsFirst go to the Go language Chinese community address: https://studygolang.com/After downloading the Go lan
the sake of simplifying the language, most APIs in the go language assume that the string is UTF-8 encoded. Although Unicode characters are supported in the standard library, they are actually less used.Byte.gopackage mainimport"fmt"func main() { varbyte for b =0;b177;b++{ fmt.Printf("%d %c\n",b,b) }}Rune.gopackage mainimport"fmt"func main() { // byte => uint8 // rune => int32 "golang你好" fmt.Println(len(s)) 0 forrange s {
When we use Golang json to marshal a struct, the non-exported members of the struct will not be able to be accessed by JSON, that is, the result of JSON encoding will not appear (that is, lowercase members cannot export).This is due to a technical problem: the name of the member in the Golang struct is not accessible if it starts with a lowercase letter, that is, JSON cannot access the member that begins wi
This article illustrates the method of Golang and PHP output Excel. Share to everyone for your reference, specific as follows:
Previously entered Excel when UTF8 is always garbled or other ways to UTF8 converted to GBK to show, oh, is actually output CSV, and then the group of friends that need to UTF8 BOM Excel to normal identification UTF8, today tested a bit, very cool, than previously saved several lines of code .
Install Daemonize
Install git environment
Yum Install Git-y
Get Daemonize
git clone git://github.com/bmc/daemonize.git
Install Daemonize
CD Daemonize./configureMake make install
See if Www.111cn.net is installed
Daemonize-v
Performing the Golang daemon through daemonize
You need to package your Golang program for the executable file (go build) and execute it through daemonize to implement the dae
The example in this article describes the use of a For loop statement in the Golang language. Share to everyone for your reference. The specific analysis is as follows:
A For loop is used to traverse an array or a number. There are also byte and rune two ways to iterate through a string with a For loop. The first is byte and the second is rune.
Copy Code code as follows:
Package Main
Import (
"FMT"
)
Func Main () {
S: = "ABC K
When you use Golang for concurrent programming, when you start a new goroutine asynchronously, the main goroutine does not know if the other goroutine is finished, and once the main goroutine exits, all the goroutine exits. Therefore, you need to control the main goroutine exit time, there are the following methods:
(1) time. Sleep ()
More brutal, not reliable, is to let the main goroutine more run for a while, the actual is not sure whether the oth
Recently, when combing the company's services, decided to pull the basic components out of service. Because the company has a variety of language development services, decided to use thrift to resolve cross-language communication.
Start a server
Thrift's support for Golang is good, and the official package provides a server base class and a simple service simple_server.go. You can implement the server to do authentication and other statistical opera
The example in this article describes the two methods of calling RPC Golang. Share to everyone for your reference, specific as follows:
Golang RPC is invoked in two ways, one in the RPC example:
Copy Code code as follows:
Package Main
Import (
"Net/rpc"
"Net/http"
"Log"
"NET"
"Time"
)
Type Args struct {
A, B int
}
Type Arith int
Func (t *arith) Multiply (args *args, reply * ([]string
The example of this article describes the Golang image image processing method. Share to everyone for your reference, specific as follows:
Golang processing picture is quite simple, I was too functional quite simple, not a thumbnail method.
Copy Code code as follows:
Package Main
Import (
"FMT"
"OS"
"Image"
"Image/color"
"Image/draw"
"Image/jpeg"
)
Func Main () {
F1, err: = OS. Open ("
The Golang itself does not provide a driver to connect to MySQL, but it defines a standard interface for Third-party development drivers. Here to connect MySQL can use Third-party libraries, third-party libraries recommend the use of Https://github.com/Go-SQL-Driver/MySQL this driver, update maintenance is better. The following shows the specific use, the complete code example can refer to the last.
Download driver
sudo go get github.com/go-sql-driv
Golang a lot of open source projects, but there are few official editions. Sometimes the choice is weak, choose a good popular components, can go a lot less detours.
Organize some of the most famous and useful open source components (continuous update) 1.web Framework
Beego
Go get Github.com/astaxie/beego
Http://beego.me2. Database
MONGO (most likely to be the official pkg)
Go get gopkg.in/mgo.v2
Http://labix.org/mgo
Mysql
Go get Github.com/go-sql-dri
function Declaration
The function uses the FUNC keyword declaration, except that the type is post-built, and the rest is similar to the rest of the language. In particular, like variable declarations, if the type of a function parameter is the same, you can add the type only at the end.
Func Add (A, b int) int {
return a + b
}
function return value
The Golang function can return multiple values, which are similar to the attributes of the return
follow the code to learn Golang language. Today we are studying the built-in data structure of the Go language: A dictionary (map).
----------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------
dictionary (MAP)
A dictionary (map) is a data structure built into the go language, a set of unordered sets of key-value pairs.
Some places are calle
There are two ways to initialize a struct in **golang: 1. Declare the key of all fields, 2. Neither declares key, but value corresponds to the order one by one defined.
Although mode 1 is cumbersome, anonymous fields may not have to be initialized when there is an anonymous field in the defined struct, and the anonymous field needs to be initialized in mode 2, otherwise the compiler will error (too few values in struct initializer)."Subclass" in
# #Golang unittest Unit Test
Golang unit tests have strict requirements on file names and method names, and parameters.
For example:
1, the file name must be named Xx_test.go
2, the method must be test[^a-z] Start
3, the method parameter must t *testing. T
Before because the 2nd did not write right, led to find a half-day error. Now really memorable, ah, little things were not carefully read.
Let's share
coverage testing in the Golang
Golang provides a number of tool chains that can be used to facilitate unit testing, analyze performance bottlenecks, provide runtime information, and so on, all of which are useful.
Go test This tool people should use more, I used to do mostly for unit testing, go to do unit testing is very convenient, but I ignored the coverage test.
How much code does the unit test cover?
solving the problem of sticky packets in TCP transmission in Golang
Author: Yu DongweiEmail:usher.yue@gmail.com What is a sticky bag.
Recently in writing https://github.com/UsherYue/ActivedRouter (a HTTP/HTTPS reverse proxy service) encountered a sticky packet problem,
If there is a network programming of the small partners should be aware of the sticky packet problem, for example: the client in the kimono
Use JSON-formatted packets for communicatio
Recently, we've been working on Docker and Kubernetes, both in the go language, in order to get a deeper understanding of Docker and kubernetes, and to learn about the go language.In order to learn in detail, a directory is listed here, will be constantly updated
Golang Study notes-Environment Building Guide (this article)
Golang Study notes-ide selection and Installation GuideContinue to update,
1. Download Protobuf compiler Protoc
Address:
HTTPS://github.com/google/protobuf/releases
Window
Download: Protoc-3.3.0-win32.zipUnzip, copy the Protoc.exe under the bin directory to Gopath/bin, Gopath/bin add the environment variable.Of course can be placed in other directories, need to add environment variables, can let the system find Protoc.exeLinux:Download: Protoc-3.3.0-linux-x86_64.zip or Protoc-3.3.0-linux-x86_32.zipUnzip, copy the Protoc under the bin directory to Gopath/bin, Gopath/bin
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.