November 2018
Intermediate to advanced
346 pages
8h 12m
English
Method injection is everywhere. You probably use it every day and you don't even realize it. Have you ever written code like this?:
fmt.Fprint(os.Stdout, "Hello World")
How about this?:
req, err := http.NewRequest("POST", "/login", body)
This is method injection—the passing in of the dependency as a parameter to the request.
Let's examine the previous examples in more detail. The function signature for Fprint() is as follows:
// Fprint formats using the default formats for its operands and writes // to w. It returns the number of bytes written and any write error // encountered.func Fprint(w io.Writer, a ...interface{}) (n int, err error)
As you can see, the first parameter, io.Writer, is a dependency for this function. What ...
Read now
Unlock full access