In Go, an error type is just an interface with Error() string signature, so every type that implements this signature satisfies it. Go also provides the errors package which allows creating so-called sentinel errors. You can find a bunch of them across all the standard library API and examples can be io.EOF ,sql.NoRows, etc.

You can create those type of errors by yourself using fmt.Errorf or errors.New .

ErrNotFound = errors.New("not found")

They come in handy in a lot of cases but when your codebase starts to grow you need to define more context to those errors to be able…

Service Objects is a highly usable pattern in Ruby on Rails that gives the ability to keep controllers skinny, models clean and remove domain logic from both. Service Objects, in my opinion, is a great example of benefits given by the Single Responsibility Principle and distribution of the responsibilities through Dependency Injection.

As general, SOLID and ideas behind it allow writing testable code, which is highly flexible for changes. These principles were promoted by Robert “Uncle Bob” Martin. The theory of SOLID principles was introduced in his 2000's paper Design Principles and Design Patterns. …

As a powerful tool, unit tests can give the ability to check every aspect of the code behavior. If you keep in mind an idea about the need for code testing, you will always write sustainable and maintainable code. Well designed code that depends on abstractions is easy to test, so code testability also can serve as an indicator of its quality.

If you have already tried to test code in Go, you probably know how useful interfaces can be. …

When it comes to integration or end-to-end testing, there is no more place for the mocks ss everything tested around real components or at least stubs for integration. Sometimes this might seem hard, even more so when you have to deal with databases.

The simplest example of the test case that includes a database in it is some web server that returns a record data by its id. To test this case, the record should be present in the test database before the actual test run.

First of all, you should check that the database is clean and ready to…

When creating a package with a client for some API, it’s critical to cover it with tests, especially if you want to put this package on GitHub for public usage, since the bug that got into the new version can cause deplorable consequences for projects that use it in production environments. After making the package public it’s your job to track its reliability and compatibility to make it usable for others.

Testing helps code maintainability, so when other users create pull requests with changes they make, you will always see if something is broken, and be sure that the code…

In JSON there are two ways to represent null values, first is when there is no value for a given key and its value is implicitly set to null, and second is when the key is present and its value is explicitly set to null.

Recently, when working on tasks for building microservices with go-swagger, I was asked to implement several scenarios for processing PATCH requests. Here they are:

  1. When a value for a key is explicitly set to null — set null value for the column at DB.
  2. When a value for a key is implicitly set to null

Roman Budnikov

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store