Go has gained fame as one of the simplest programming languages, including its simplicity in writing and reading code, in most cases, simpler support for the code base. We talk about several advantages of Go, thanks to which we at SimbirSoft used it in a number of high-loaded projects with various architectures, both web-based and microservice (SOA).
Application
This system language is good for most network tasks, any microservices and macroservices, web services, and also for system tools - it’s not for nothing that many DevOps experts love it. Go finds its use in Machine Learning, and some developers even write websites with it. In our practice, we turned to Go when we developed separate CRM and software products for internal use, for example, for insurance companies. The standard Go language repository also has a package for mobile development, this package is still supported, although there are more suitable tools for this.
Go: development and recognition
At Google, the development of the Go language began in 2007. Prior to this, the company used Java, Python and C ++, however, they had certain drawbacks (in particular, high memory consumption) or limited use. Then, Google began to develop a new language for their needs.
')
What are the requirements for the language:
- One executable file (no dependencies)
- Quick compilation
- Fast runtime (at least on a par with Java and C ++)
- Garbage collector minimizing resource leaks
- Optimization for multiprocessor systems
- Static typing
- Minimalism
- Syntactic lightness
- Multi-paradigm (imperative, functional, object-oriented)
For those who do not work with Go, we briefly recall the history of its creation. The language specification on Google began to be thought out in 2007. Release 1.0 took place in 2012, and in 2015 release 1.5 was released, already without a single line of C ++ code. From this point on, the language compiles itself, which made it possible to speed up the development of individual tasks on Go.
The average age of recognition of a new language in the community is about 10 years, but Go is already among the most requested languages. In June 2019, Go rose to 15th place in popularity in the world, according to the
TIOBE index, adding three positions in a year. Among the reasons for its success are the following:
- Strong standard library
- Steep standard tuling
- The most necessary functions are presented in the “box”, and libraries are given to open source.
- Very friendly community
For example, the following packages are included in the standard library (the list is incomplete):
Illustration - github.com/ashleymcnamara/gophersIf you are not satisfied with the speed of your application or other parameters, you can work with the profiler from the “box”. For this you need:
- Register profiler import: import _ "net / http / pprof"
- Add an http server to get results from the profiler: go http.ListenAndServe ("0.0.0.0:8080", nil)
Go tools
One of the advantages of Go is an extensive set of standard tools. We chose some of the most interesting utilities, in our opinion (in fact, there are many more):
- benchcmp - benchmarks comparison, performance before and after changes
- go tool cover - analysis of code coverage by tests
- godoc - comments based documentation generation
- goimports - import analysis (deleting unused, adding missing)
- gorename - refactoring
- present - presentation presentation
- go vet - linter of common errors
- go test - run tests and benchmarks
- go fix - fix changes when changing API (before release 1.0)
- go tool pprof - profiling
- Go fmt - code formatting by code style
- Race detector - finding race data at runtime
Competitiveness
Another strength of Go is that it is easy to write competitive code in this language. To do this, you simply use keywords before calling the function.

Learning go
If you want to program on Go, the start will take relatively little time. The developers - Core Team - support the A Tour of Go course in several languages, including Russian. This course can be taken literally 1-3 days. In terms of learning, Go is one of the easiest languages.
So, what to read:
ORM in Go
There are opinions that one of the weak points of Go are ORM. Perhaps this is partly due to the fact that the language is young - it is just starting to develop many of the necessary tools. In particular, you can use the database / sql package for working with databases. What are the requirements for the package:
- Common package for all sql databases
- Portable: does not contain any features in the field of work with databases. Ideally, everything should work correctly if you change the driver.
- Converting Go types to standard database types (this should be able to handle specific types)
- Contains connection pool
- Thread safety for gorutin
Sample SELECT query using database / sql
defer rows.Close() for rows.Next() { var message string err := rows.Scan(&message) if err != nil { log.Panic(err) } fmt.Println(message) } if err := rows.Err(); err != nil { log.Panic(err) }
As you can see from the example, a lot of template actions will have to be performed every time. For example:
- close the rows object: defer rows.Close ()
- check for errors err: = rows.Err (); err! = nil it is not clear for what reason rows.Next () returned false to us
From all this, I want to use something more universal and simple, for example, ORM.
Types of implementations of ORM
When developers are faced with the question of choosing ORM to work with Go, they are often rated by githubs. When we chose ORM for ourselves, Beego had the best rating (18 thousand “stars”). However, in practice, ORM is part of the framework, so the assessment is not completely objective (if you choose only ORM). Also among the leaders Gorm, which has been developing since 2013, supports transactions and has many other advantages.

However, as our experience of acquaintance with Gorm has shown, certain problems are possible when using it, especially when testing: for example, a data race or deleting a foreign key. We can assume the following causes of similar errors in the Gorm:
- Commits immediately to master
- Missing tags
- Unpredictable sql builder
At the moment, in our work, we prefer several ORMs that do not use the interface {} - this is Kallax, Reform and Sqlboiler. Usually we use the
Golang package for migrations and the
orm-bench repository with ORM benchmarks on Go. In this case, you should not chase only for benchmarks. More often, speed is not as important as the quality of the code and its functionality.
Summing up
The benefits of the Go language for the developer and for business include increased development productivity, the ability to use fewer servers, syntactic ease and quick training for new developers, a large set of tools and a friendly community. Despite the fact that it is a young language, it is constantly growing and developing. Go features make it the optimal language for performing various projects, from network tasks to microservices and blockchain.
The article was prepared on the basis of our report at the Hot Backend in Samara.