Do less, Enable more
I ❤️
Techkaro
NgGirls
Dawood UET
JS Dive
JS Meetup
React KHI
Deep dive into specific topic of Golang or its good practices
In a recent study published by HackerRank of over 70 thousand developers, 37.2% indicated that Go is a language they wish to learn in 2019. No other language scored as high
One of the goals of the Go project were to eliminate the slowness and clumsiness of software development at Google. The language was designed by and for people who write and read and debug and maintain large software systems.
– Rob Pike, Creator of Golang –
Golang was originally build to solve Google's problems
And has big Problems!!!
If the main purpose of functions or methods is returning a bool type value, the name of function or method should starts with Has, Is, Can or Allow, etc.
Constant should use all capital letters and use underscore _ to separate words.
A variable name should follow general English expression or shorthand.
In relatively simple (less objects and more specific) context, variable name can use simplified form as follows:
If variable type is bool, its name should start with Has, Is, Can or Allow, etc.
Gofmt reformats Go source code, whereas golint prints out style mistakes.
To check files for unnecessary parentheses:
gofmt -r '(a) -> a' -l *.go
To remove the parentheses:
gofmt -r '(a) -> a' -w *.go
To convert the package tree from explicit slice upper bounds to implicit ones:
gofmt -r 'α[β:len(α)] -> α[β:]' -w $GOROOT/src
Installation:
go get -u golang.org/x/lint/golint
Usage:
golint ./../main.go
Create a new, empty directory somewhere outside $GOPATH/src, cd into that directory, and then create a new source file, hello.go:
package hello
func Hello() string {
return "Hello, world."
}
At this point, the directory contains a package, but not a module, because there is no go.mod file.
Let's make the current directory the root of a module by using go mod init
$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello
The go get tool will find the package, on GitHub in this case, and install it into your $GOPATH.
go get github.com/gobuffalo/flect
Packages are often being updated by the original authors to address bugs or add new features. When this happens, you may want to use the latest version of that package to take advantage of the new features or resolved bug. To update a package, you can use the -u flag with the go get command:
go get -u github.com/gobuffalo/flect
Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.”
— Rob Pike
Process 1
Thread 1
Thread 2
10
20
30
40
50
60
70
80
90
100
110
120
130
Task 1
Task 2
Process 1
Thread 1
Thread 2
10
20
30
40
50
60
70
80
90
100
110
120
130
Process 2
Thread 1
Thread 2
Thread 3
Thread 1
10
20
30
40
70
Process 1
1
3
2
4
2
3
1
4
4
3
1
2
goroutine
thread
goroutine
channel
// buffered
ch := make(chan Task, 3);
// unbuffered
ch := make(chan Task);