Important Characteristics of Go: Error Variables

Let’s learn how to use error variables to differentiate between input types.

Using error variables to differentiate between input types

Now, let’s see a technique that uses error variables to differentiate between various kinds of user input. For this technique to work, we should go from more specific cases to more generic ones. If we are talking about numeric values, we should first examine whether a string is a valid integer before examining whether the same string is a floating-point value because every valid integer is also a valid floating-point value.

Coding example

This is illustrated in the next code excerpt of process.go:

Get hands-on with 1200+ tech skills courses.