httpclient and (decorating) middleware in golang
I am trying to grasp how the following code example works. It wraps (decorates) a standard http.client with 2 middleware functions (Logger and BasicAuth) that are invoked when making client (RoundTripper) calls. The setup/initialization is as follows: package decorator import ( "log" "net/http" "os" ) // Setup initializes our ClientInterface func Setup() *http.Client { c := http.Client{} t := Decorate(&http.Transport{}, Logger(log.New(os.Stdout, "", 0)), BasicAuth("username", "password"), ) c.Transport = t return &c } The problem is that I don't exactly understand what happens in the Decorate
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.