Golang's Pit (continuously updated in ....) )

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

Using Golang to develop a new project for some time now, it's getting a little bit disappointed with go, but fortunately there's no despair.

At the beginning of the "Go Speech Programming" (Xu Xiwei), the most let me in the light of the fact is not the co-process (this has been listening to too much ...) ), but the marshal and unmarshal of the JSON, and then learned that go can set tag properties on struct members. Simply thinking about it and discovering that this feature would make the code look a bit more elegant if it could be ported to our current Python code.

As the project progresses, there is a deeper understanding of the features of go, and then there is a growing sense that some of the things that looked great before are not as good as they might seem.

Now open the spray

  • Since Golang is a strongly typed language, when JSON unmarshal is not a pointer in the definition of a struct, it is not possible to tell whether a default value has been received or the parameter is not in the JSON package. This is not really a serious problem, just one of the places where you need to be careful when programming.

  • Due to the use of peewee, resulting in Golang several ORM implementation is not very satisfied. In PeeWee, a dirty member is hidden behind the model, which can record the changes you have made to those columns, and the various black spells (such as the ability to notify objects when modifying an object's members) also make Python's implementation of the ORM very natural and flexible.

  • Go said that in order to keep the syntax simple, using a few keywords, but in fact, in order to achieve certain functions, but also hide some strange things in the inside: such as Iota, to the _test.go end of the test code, link can specify the value of certain variables .... I don't know that with the depth of study, What strange things will suddenly jump out of the day. But think about it less than C + +:)

  • In order not to let the user feel free to use the Go routine ID to do something, so the go routine ID to hide it .... In the official parlance, when using goroutine local storage, it would be troublesome to forget to clean up. Here is a more useful GLS library: Tylerb/gls

  • The most memorable is the implementation of the official library. The log packet has little practical value, and you will feel that this thing is too casual to write, compared to the various handler and formatter in the Python logging package. We recommend a log package that is more useful: inconshreveable/log15. Later I probably will be based on this implementation of a LOG16 bar:)

  • For Go novel package import way .... compatibility issues between versions can eventually be avoided, so a vendor is made. But this is not finished, once compiled a project when prompted to find a package, and then ran to the corresponding Git repository on the look, the author said "has moved to XXXX" ...

  • Suppose you have an open source library A in your project and use another open source Library B, where B also uses a, but the A is placed in the vendor of B, then when compiling your code, Golang actually compiles the two as a different package. Well, it's not really a problem, but in case a uses a global variable in another package C!! GG

Say something good.

Spraying so much, golang inside a lot of bags sometimes will bring a very unexpected surprise, from the design or realization of the function, let a person in front of a bright.

    • Golang.org/x/net/trace: You can create a trace object and then use traceobj.lazyprintf to record some log information and start the default HTTP server at the same time so that you can http://default-server/debug/requests This page looks at all the trace objects that are active and closed and their information.

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.