Читать книгу Practical Go - Amit Saha - Страница 26

Interface Type

Оглавление

To use the various library functions and to write testable applications, we will be making extensive use of interface types. For example, we will be making extensive use of alternative types that satisfies the io.Reader and io.Writer interfaces to write tests for applications that interface with the standard input and output.

Learning to define a custom type that satisfies another interface is a key step to writing Go applications, where we plug in our functionality to work with the rest of the language. For example, to enable sharing data across HTTP handler functions, we will define our own custom type implementing the http.Handler interface.

The section on interfaces in “A Tour of Go,” https://tour.golang.org/methods/9, is useful to get a refresher on the topic.

Practical Go

Подняться наверх