Implementation of Kafka middleware based on Golang

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

These two days with Go wrote the first project, still in the demo phase, follow-up will continue to record some of the pit points about go development.

The project, called Bigpipe, is designed to solve asynchronous HTTP calls between services, which is very simple to implement with go, and is also good for concurrency.

I made a simple sharing PPT for the project to download.

Project Address: Https://github.com/owenliang/bigpipe, editor must use Gogland, error hints too strong, it is difficult to write the wrong code!

Now there are a few notes:

    • Configuration file I use JSON, because go is strongly typed, so parsing json is very painful, but open source Library I do not trust, so use the standard library JSON slowly.
    • A go file in a directory belongs to a package, the package is the name of the directory, the package calls each other does not need import.
    • The pipe is referenced and does not require pointers.
    • When you format a string, the string* and string are different, and the former prints the pointer, which is the value.
    • Log library I wrote it myself, with channel transmission to ensure concurrency security, single goroutine sequential write files.
    • The context library is a relatively unpopular but must be used for something, you can take a special look.
    • The HTTP library is very powerful, both for the server and the client, both asynchronous and concurrent.
    • Go comes with Go get package management is too difficult to use, does not automatically download dependencies, there is no version of the concept, you must use third-party package management tools.
    • Goroot points to the Go installation directory, Gopath points to the project directory (it looks for the code in the SRC directory), both of which are used to search for code in the import.
    • Where to put the program's entrance, but be sure to define it as the package main.
    • Analysis Go program performance can be used pprof, it can directly draw the call graph and view in the browser.
    • The Go program needs to specify the number of threads according to the runtime package after booting, otherwise all CPU cores may not be used.
    • Using interface abstract interfaces to rely on abstractions rather than relying on implementations is consistent with the abstraction of C/c++/java, but the form is too special to be used.

Follow-up will continue to improve the project, casually record some go experience.

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.