27

Notes on Go Development

 5 years ago
source link: https://www.tuicool.com/articles/hit/v2uI7vA
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Summary

Notes on development with the Go language.

Installing Go

To install Go on Windows, download it from the official Website . Choose the 64-bit Windows installer package for the current version, unless you know that you need a different option.

To install Go on macOS, use Homebrew .

To install the current version of Go on Linux, use the package from the official Website, or a Docker image . Docker, Inc. maintain the Docker images. Linux distributions supply versions of Go, but these will frequently be older than the current release.

Choosing a Code Editor or IDE

My current text editor is Oni , a desktop version of Vim. You may prefer Visual Studio Code or Atom , which are high-quality and customisable editors that have plugins for Go. All of these editors are free.

Essential Tools

There are a number of de-facto standard utilities and libraries for Go software development, but a few tools are so fundamental that you should install them even before you begin to write Go code.

Git for Version Control

If you do not already use version control, you should install Git on your system. Git is now effectively the standard version control tool for developers.

Version control is obviously vital for collaborating with other programmers. It also enables you to efficiently copy your application to other systems for testing, deployment and backup.

If Git is installed, Atom and Visual Studio Code provide you with access to information and features from Git directly in their user interfaces. If you use Visual Studio Code, you should also consider installing the Git Lens extension, which enhances the integration with Git.

Code Quality

Use the Go Meta Linter to run code quality checks. Plugins enable some popular text editors and IDEs to integrate this, so that your code can be formatted and checked as you work. The Go plugin for Atom automatically installs Go Meta Linter.

The Go Report Card service will analyse any Go software in a public Git repository, using some standard tools. You do not need to do anything to enable the Go Report Card. If you wish, you may add a badge to the README that links to the Report Card report for your project.

Dependency Management

Set up dep in your projects to manage the dependencies. Future versions of Go will include a replacement for dep , but it is the current standard.

Other Popular Tools and Libraries

  • Delve - Debugger
  • GoReleaser - Release automation for Go projects
  • go-cmp - Package for comparing Go values in tests
  • Packr - Embeds files into Go binaries
  • Viper - Configuration for Go applications

Error Handling

Go assumes that error objects should be designed to match the needs of the particular application. If you would like a simple implementation of these, use the errors package.

Web Applications

You can develop Web applications in Go with just the standard library and a few third-party packages, but this requires you to handle every feature and technical decision yourself. These frameworks provide a structure and sets of tested components for your applications:

  • chi offers a minimal but very high-performance framework for Web API services.
  • Buffalo is a full set of integrated tools and components for Web sites and applications.
  • Echo provides a convenient framework for APIs.
  • Go kit is specifically for building individual microservices for enterprise architectures.

Cloud services such as Google App Engine and Heroku provide low-maintenance hosting for Go Web applications.

To produce applications for AWS Lambda , use the Apex or Sparta frameworks.

Web Clients

The standard library for Go includes HTTP server and client software. These support both HTTP 1.1 and HTTP/2. Use resty if you would like a more convenient API for REST client software.

Colly provides a framework for Web scraping.

Accessing Databases

Go includes support for SQL in the standard library. Add sqlx to your project to extend this SQL support with additional features. You will need to install drivers for the specific brand of database that your code will access.

If you need an Object Relational Mapper(ORM), consider GORM , pop or sqlboiler . GORM and Pop both offer an ORM that can create and fully manage an application database throughout the life of the system. SQLBoiler generates Go code from an existing database.

To embed a key-value database within your application, use bbolt .

Developing Command-line Tools

To create command-line tools with Go, use the Cobra framework.

Robotics and Internet of Things

Gobot is the main package for working with robotics and hardware, such as Arduino boards.

EmGo is an implementation of Go for programming embedded systems.

Resources

Interactive

Documentation

Books


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK