Go Web Programming

Source: Internet
Author: User
Tags sqlite database
This is a creation in Article, where the information may have evolved or changed.

Recently, a book titled "Go Web Programming" appeared on the Web, detailing all aspects of Web programming using the go language. In particular, this book was written on GitHub in an open source manner. Recently, Infoq interviewed the author of the book, Mr. Xie Mengjun, and asked him to come and talk to you about the go language and the open source books he wrote.

InfoQ: Please let me introduce you briefly.

Xie Mengjun: Hello, my name is Xie Mengjun, can call me Asta, currently working in Grandcloud, responsible for the grand cloud distribution product development. Cloud distribution is what we normally call a CDN system.

InfoQ: What prompted you to write "Go Web programming"?

Xie Mengjun: I used to be mainly engaged in PHP, Python and other web development, and then to Grandcloud after contact with more than C + + and other underlying things, I would like to learn the underlying technology. Later see Xu Xiwei's blog, learn the Go language. Go comes from the author of the B language and the hand of the UNIX founder Ken Thomson, and there are a lot of cows behind it, and the language is designed to be system-level language. This coincides with my goal of learning, so I started the road of self-study. In the process of self-study, it is found that go in the network programming this piece for developers to provide a lot of convenience, both C and other language performance and debugging capabilities, and Python and other language dynamic characteristics, but also built-in multi-core concurrency support.

In the course of learning, I found that Go in the network programming performance is very good, and I was mainly engaged in web development, so I would like to write "Go Web programming" Such a book, mainly to the previous in the web development of some experience and Go language together, to do some summary, to some of the later enlightenment, I hope to help the students who want to learn the go language.

InfoQ: The book you wrote was open source on GitHub, so why would you take that way?

Xie Mengjun: using github mainly I have seen a book called "PHP Extension development and kernel applications", this book is written on GitHub, I saw after shocked, incredibly can still write books, and markdown is so concise, GitHub's support for Markdown was also very good, so it was decided to write the book on GitHub.

What features of Infoq:go language are most appealing to you? What are the features that make you feel you need further improvement?

Xie Mengjun: The go language attracts me mainly in the following points:

  1. It is a system-level language, statically compiled, and is a C-series language.
  2. There are many built-in libraries that are very similar to Python.
  3. The syntax is simple enough and the introductory learning cost is low, which is suitable for me to switch from PHP and Python.
  4. Fast, take the simple page, I use PHP development concurrency can reach 500 very good, but with go easy to tens of thousands, this is incomparable performance improvement, and with go development efficiency and PHP almost.
  5. From Google's hand, and there are a bunch of cattle in the maintenance, based on BSD open source, community active.
  6. Open source projects give me a lot of confidence, a few open source system: vitess (YouTube Database proxy system), NSQ (a real-time information Processing system bitly), Skynet (lightweight distributed Service framework), seven cattle Company all with go development, 360 development of the class imessage application, support tens of thousands of users, while a single server long connect 80w, these systems are their online run, which gives me greater confidence to use go to develop high-performance, high-stability applications.

The main disadvantages:

  1. Some libraries are immature, as is the case with processing.
  2. CGO the Windows system under the compiler is very troublesome, take the SQLite database driver, in the window under the compiler will encounter a lot of trouble.
  3. Runtime is not mature enough, GC is not very good, but heard that go 1.1 version will have a relatively large performance improvement.
  4. Go's open-source projects aren't enough. I think the development of a language is not only the language itself, but also the promotion of big companies or good projects.

InfoQ: Some say go is the C language of the internet age. What are the advantages of the go language, and what are the areas that need improvement?

Xie Mengjun: The go language really absorbs a lot of C language features, Ken Uncle is the founder of UNIX, many used to see C not accustomed to the place, this time go inside has been improved, such as {} The line, () of the removal, forced formatting, remove the end of the semicolon and so on. And why is go called the internet age of C? I think that go at the language level to support concurrency, through the simple keyword go can take full advantage of multicore, which for the development of the hardware era, so simple to make full use of hardware multicore, this is how important a feature Ah! However, compared to C, go also lacks some high-quality third-party packages, such as OpenGL, so the inside of go also supports the use of CGO directly called C language code.

InfoQ: Some people think that the go language will catch up with Java later. What are the advantages of the go language, and what are the areas that need improvement?

Xie Mengjun: I feel, go to catch up with Java still do not know to wait for what age. First of all, Java is currently very stable in enterprise applications, and Java-based applications are many, there are many libraries, I think Java will have a lot of similar JVM-based languages appear, such as Scala, I think go beyond Java is unlikely. But the pros of go are also obvious compared to Java: simple, simple enough. Remember when a go creator Rob wrote an article "Boulevard to Jane", which is the process of creating a go language. I think the experience of this batch of old programmers is worth learning, let us use the go language to simplify complex things, simple things simple, go may be such a language.

InfoQ: Are you already using the Go language extensively in your project, and what are the main areas of it?

Xie Mengjun: The project I'm currently developing is mostly developed with go, but I'm still using JavaScript to render on the page, and my current development pattern is the JavaScript rendering front-end +restful API, which interacts with JSON data. There are several reasons for developing this model:

  1. I think the JavaScript rendering page is much better than the go template, and JavaScript has a lot of existing libraries, it is easy to make many effects, my idea is that no matter the White cat black cat, will catch mice is a good cat, appropriate language used in the right place.
  2. Go Development API is quite fast, and performance is very high, is PHP, Python and so on incomparable.
  3. Designed as a restful API, the system is relatively easy to expand, and extensibility is better.

At present, the internal short domain name service uses the Go+redis development, the video Live scheduler all uses the go development, the internal system monitoring and the automatic operation and maintenance system adopts the form of the Javascript+restful API development, and some other edge projects are using go development.

At the same time, I have developed two open source projects:

  1. Beego: A Go development framework that mimics Python's tornado system development, and several systems are now developed based on that framework.
  2. Beedb: A Go Language ORM library that can manipulate database data as if it were a struct. At present, the API interface of our internal I was developed using this ORM.

InfoQ: What features do you think the go language has in terms of web programming that makes it more advantageous?

Xie Mengjun: The front also said that the go language design is the system-level language, so he has the advantages of performance above. Second go in the web development of the built-in Net/http package for the development of the web is very convenient, users can easily build a Web application. Students familiar with PHP may be familiar with the nginx+fastcgi configuration, but go development of the application will not need nginx, because it can monitor the network, parsing the packet, and not rely on anything, you compile and then throw to the server up, which saves some of the deployment of the part. Finally, go concurrency support, we have heard Moore's law, the hardware will be more and more quickly, the CPU will be more and more, then this feature of go to let us these programmers from the previous multi-threaded processing freed, let go language runtime to help us do this thing, Why not use go to write the Web?

InfoQ: What are your suggestions for readers who start learning the go language and look forward to applying it to the project?

Xie Mengjun: I've just started learning about the go language, and I suggest reading some of the official articles is very helpful, if you are sensitive to English, then look at the book I wrote "Go Web programming."

Before you apply go to your project, I want you to have some idea of the features of go. The features of the go language are now largely determined, and the next versions are based on performance improvements, which are not expected to be available in the new features. Then, it is recommended that you read more of the go built-in package source code, because these packages are developed in the go language, for us to write the go code and a lot of help to see how these cattle people write code. There is a good saying: Learn the cattle, copy the cattle, beyond the cattle, and finally we become cattle people.

Finally, it is hoped that the domestic technical people will learn the go language, whether it is now for you have no use, but I can certainly say that the future is certainly useful, for you to develop a project with the role of expanded thinking, I am now learning node. js, Erlang, I learned they are to better develop the Go project, Learn some of the features of other languages.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.