liveBook · Manning

Validation

As explained in Go in Action, Second Edition

Validation is the process of checking that input data satisfies required structural, type, and semantic constraints.

Validation turns untrusted configuration input into data the application can safely use. In Go, parsing with encoding/json checks JSON structure and Go types while returning errors for malformed input; custom unmarshaling adds domain-specific rules such as URL validation. section 10.5.1

Configuration validation

A configuration containing name, version, debug, port, and host fields can be decoded into Config. Unmarshal rejects malformed JSON or incompatible types; custom unmarshaling then checks that host is a valid URL. A separately parsed port must fall between 1 and 65535, while debug accepts the Boolean forms supported by strconv.ParseBool.

How Go in Action, Second Edition covers it

How deep it goes
Descends from parsing and type checks to range checks and custom URL validation through UnmarshalJSON.
Examples
Uses configuration JSON, template dispatch, Host URL checks, bounded port parsing, Boolean parsing, and formatted configuration values.
What it assumes
Assumes Go structs and typed values while demonstrating conversion from raw JSON or strings into validated application data.
What you can do after
Builds validation from scratch with encoding/json, custom UnmarshalJSON methods, and strconv parsing functions.
How it connects
Connects JSON, Go structs, encoding/json, custom unmarshaling, configuration parsing, and strconv conversions.

Also explained in

Compare how 30 books explain validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.