Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package eventlog | |
| 6 | |
| 7 import "net/http" | |
| 8 | |
| 9 // A ClientOption is an optional argument to NewClient. | |
| 10 type ClientOption interface { | |
| 11 apply(*clientSettings) | |
| 12 } | |
| 13 | |
| 14 type clientSettings struct { | |
| 15 HTTPClient *http.Client | |
| 16 } | |
| 17 | |
| 18 func (cs *clientSettings) Populate(opts []ClientOption) { | |
|
djd-OOO-Apr2017
2016/11/21 04:02:24
This seems like overkill today – can we just have
mcgreevy
2016/11/21 04:51:06
Done.
| |
| 19 for _, o := range opts { | |
| 20 o.apply(cs) | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 type httpClientOption struct { | |
| 25 *http.Client | |
| 26 } | |
| 27 | |
| 28 func (opt httpClientOption) apply(cs *clientSettings) { | |
| 29 cs.HTTPClient = opt.Client | |
| 30 } | |
| 31 | |
| 32 // WithHTTPClient returns a ClientOption that specifies the HTTP client to use a s the basis of communications. | |
| 33 func WithHTTPClient(client *http.Client) ClientOption { | |
| 34 return httpClientOption{client} | |
| 35 } | |
| OLD | NEW |