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.
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.
- Getting Started
- Basic
- Data Types
- Functional programming
- Err handiling
- defer
- recover
- file listing server (Practice project)
- Goroutine
- Http
- http (http request)
- Reflect
- Tcp
- RPC
- rpc(basic using)
- Interface
- interface (
duck-type
,interface
)
- interface (
- Algorithms
- data-structure (
tree
,queue
,linklist
,hashtable
.eg) - algorithms (
sort
,josephu
.eg)
- data-structure (
- Comprehensive practical
- crawler(
single-task
,Concurrent-crawler
) - crawler_distributed(
distributed
)
- crawler(
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
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 is done using 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