Skip to content

TomorrowWu/learn-golang

Repository files navigation

Playground and cheatsheet for learning Golang

This is a collection of Golang that are split by topics and contain code examples with explanations, different use cases and links to further readings.

It is a playground because you may change or add the code to see how it works. Altogether it might make your learning process to be more interactive and it might help you to keep code quality pretty high from very beginning.

It is a cheatsheet because you may get back to these code examples once you want to recap the syntax of standard Golang statements and constructions.

How to Use This Repository

This repository is source code that belong to a Video tutorial about Golang. The video is maked by a Google engineer. If you can understand Chinese,you can watch it.If you don't know Chinese, don't worry, just write the code.

So normally you might want to do the following:

  • Find the topic you want to learn or recap.
  • Look at code examples and assertions to see usage examples and expected output.
  • Change code or add new assertions to see how things work.
  • Run tests and lint the code to see if it work and is written correctly.

Golang Mind map

Table of Contents

  1. Getting Started
  2. Basic
  3. Data Types
  4. Functional programming
  5. Err handiling
  6. Goroutine
  7. Http
    • http (http request)
  8. Reflect
  9. Tcp
    • tcp (basic using)
    • chatrom(a practice about tcp-programming)
  10. RPC
    • rpc(basic using)
  11. Interface
  12. Algorithms
  13. Comprehensive practical

Prerequisites

Installing Golang

Make sure that you have Golang installed on your machine.

You may check your Golang version by running:

go version

Make sure that you have Golang environment variable on your machine.

Installing dependencies

Install all dependencies that are required for the project by running:

go get github.com/golang/example/hello

Testing the Code

Tests are made using go-test comand.

You may add new tests for yourself by adding files and functions with test_ prefix (i.e. test_topic.go with func TestSubTopic(t *testing.T) function inside).

To run all the tests please execute the following command from the project root folder:

go test

To run specific tests please execute:

go test ./test_topic.go

Linting the Code

Linting is done using golint.

Golint

To check if the code is written with respect to Golang style guide please run:

golint ./src/

In case if linter will detect error (i.e. missing-docstring) you may want to read more about specific error by running:

main.go:5:6: exported type Hero should have comment or be unexported

More about Golint