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
As a low-level technology, blockchain technology from the initial digital money to smart contracts to the current industry scenarios distributed application implementation, since 2008, 10 years ago, the blockchain from the original theoretical concept to today's actual scenario application landed, although questioned but have been hard to move forward. Especially in the last two years, the re-construction of the existing industry logic in blockchain has made it undisputed the next development of
Tags: turn database query host UID for TCP user return UTF8Just beginning to contact Golang, just write down a few methods, the principle is not very clear, temporarily just can achieve the point, essay points 1. Database connection var {
= ""
= "" = "" = ""}//Return DB connection
func dbopen () (Db_obj *sql. DB, err error) {
db_obj, Err_open: = sql. Open ("MySQL", dbhostuser+ ":" +dbhostpassword+ "@tcp (" +dbhostip+ ":"
DEP Golang Package Management usage Records
DEP is one of the Golang project dependency management, is an official experimental project, the current update is very frequent in the high-speed development period, so the choice of DEP as a Golang dependency manager is more reliable. (Known glide only support no longer developing new features)
Currently DEP v0.5.0 re
This is a creation in
Article, where the information may have evolved or changed.
Deploying Golang apps to Docker
Project Address: Https://github.com/EDDYCJY/go ... (Get in the car, support a wave)Original address: Https://segmentfault.com/a/11 ...
Note:
You need to install docker and match the image source before you start.
This section of the source code on the f-20180324-docker branch
Start the project catalog from this section go-gin-e
This is a creation in
Article, where the information may have evolved or changed.
When a new thing appears, it should be to solve some problems arise, otherwise there is no way to shift the focus of people, this is not nonsense. Lu Xun said that I have always been not afraid with the worst malicious to speculate on the Chinese people, but I still behold, also do not believe that the inferior ferocious to this point. Lu Xun also said that mass ignorance and forgetfulness are easily incited. I do
bloated, and the lack of system programming genes, after all, it is enterprise development origin of the last I chose Erlang, because it is excellent in the network layer performance, At the same time fault tolerance and robustness are very good, its virtual machine is the only one comparable to the JVM, but also the OTP super-heavyweight weapons, almost can be a Kill network layer application, but according to my summary it has a mishap and a soft rib, this point behind the expansion, It can b
Five phases of file integrity monitoring, file integrity monitoring
If the file integrity monitoring (FIM) solution is deployed well, the benefits are great:
If you see unexpected or uninterpretable file modifications, you can immediately start the investigation: if the investigation finds that the system is intruded, the problem can be quickly solved.
These chan
Linx monitoring sharing-Key Process Monitoring (mysqld) + email reminder, linxmysqld
Key Process Monitoring
Mysqld: The process exits and an alarm is triggered. If you do not exit, you will be notified of monitoring mysqld (cpu (> = 100%) | mem (> = 80%) and the mysql status information will be collected and analyzed;
This article describes some of the Zabbix monitoring JVM and Tomcat monitoring items Chinese interpretation, suitable for a certain basis for the people to see, for the Zabbix version of 2.4.4, memory recovery management mainly relies on the CMS and parnew mechanism. If there is a wrong place, please point out.Because the table can not be copied directly, here only upload the picture, you need to copy the s
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.