This series of articles will document my Golang learning journey. The knowledge structure may be messy or basic, but the ultimate goal is to develop golang-based microservices. Article knowledge is very basic, mainly to try the back-end stack of the front end to see, back-end big guy don’t look, it is likely to waste your time. Welcome to discuss progress, the title of the article does not represent the content of the article…

Psychological process analysis

Here’s why I’m writing about microservices. Since I learned the language Golang, I have been doing front-end development, and usually use Node.js and Laravel to write back-end projects, but I always feel it is difficult for Node.js and PHP to go to the bottom of the operating system (my subjective feelings), and I always want to have a language that can go into the bottom of the system. The C family of languages is well-deserved at satisfying the bottom of the system. But the entry time is too long, the basic skills are also very high requirements. Finally, I found Golang. I went deep into the bottom layer, and there are corresponding solutions for network development, Web development, and micro-service development that I have always wanted to try. I feel lucky to catch the tail of the Internet wave. The next WAVE of 5G Internet of Things can not be missed. In the Internet era, edge computing, distributed, micro-services and big data are all good directions. Golang language, as a C language in the Internet era, can well meet these needs. Take advantage of this opportunity to overtake on the Go curve.

Problems encountered in use of Go

0. Download the image file

This problem began to encounter their own learning enthusiasm spent, is really very pit, and then found the way to set up proxy mirror: goproxy. IO to lay this pit in the past. During the period also tried a lot of stupid methods, directly download github repository source code, the results found that the download package still depends on, keep downloading, keep reporting dependency errors… And so on all the dependence on good after the day lily are cool.

1.GOPATH

I installed Go and ran it

go env

I found that my GOPATH configuration was terrible, and I set many paths. Maybe IT was because I just tried to Go and only focused on the online tutorial configuration, without a thorough understanding of the meaning of GOPATH, so I thought about how to make the configuration simple and clear, and finally found the configuration method.

vim ~./bash_profile

$HOME/go = Users/winyh/go; $HOME/go = Users/winyh/go; $HOME/go = GOPATH; Such as/usr/local/bin: / Users/winyh/go) the first path.

export GOPATH=$HOME/go

Add $HOME/go/bin to PATH. You can run commands in this directory

export PATH=$PATH:$HOME/go/bin

2. Set the Go project directory

Create a new one in the GOPATH directory

bin pkg src

* * * * * * * * * * * * * * * * * * * * * * * * * * * * The generated binary files will be saved in the bin directory. Switch the directory to bin to directly execute the tech project we developed./tech.

3. Project package dependency

I chose the govendor tool, which I think is quite useful.

go get -u github.com/kardianos/govendor

The specific usage method can be read by yourself in the documentation, because I often come into contact with Node.js and Laravel. To explain my understanding, it is similar to the NPM of Node.js in PHP, which is the third-party package dependency management. In your own project, govendor Init initializes a vendor folder and vendor.json package dependency log file. Equivalent to vendor and Composer for Laravel and package.json for Node.js.

4. Afterword.

Step by step in the process of trying to solve the problem of feel very with a sense of accomplishment, of course, there will be agitated, such as a wall, is obsessed with new concept, but continue to try a few times after trial and error will be the root cause of the problem and the underlying principle will be more and more clear, crossing go good, friends come on!

Any good microservices framework needs to address these three fundamental issues:

  • Service discovery
  • Synchronous communication
  • Asynchronous communication

The next article will delve into Consul, the default service registration and discovery center for Micro Micro Services Framework – Golang-based Microservices – Consul