November 2017
Intermediate to advanced
670 pages
17h 35m
English
Let's look at our decorator.go implementation. It's in the 02_decorator directory, and the package name is decorator:
package decoratorimport ( "log" "net/http" "sync/atomic" "time")type Client interface { Do(*http.Request) (*http.Response, error)}// ClientFunc is a function type that implements the client interface.type ClientFunc func(*http.Request) (*http.Response, error)func (f ClientFunc) Do(r *http.Request) (*http.Response, error) { return f(r)}
The ClientFunc function is a function type that implements the Client interface.
We also define two additional methods that act as the getter and setter for the ratelimitDuration value:
var ratelimitDuration time.Durationfunc (f ClientFunc) SetRatelimit(duration ...