(options ...Option)
| 104 | } |
| 105 | |
| 106 | func initClient(options ...Option) *Client { |
| 107 | if c == nil { |
| 108 | var opts opts |
| 109 | for _, opt := range options { |
| 110 | opt(&opts) |
| 111 | } |
| 112 | |
| 113 | if opts.apiURL == "" { |
| 114 | opts.apiURL = apiURL |
| 115 | } |
| 116 | if opts.refreshInterval == 0 { |
| 117 | opts.refreshInterval = time.Hour |
| 118 | } |
| 119 | |
| 120 | c = &Client{ |
| 121 | options: opts, |
| 122 | drivers: make(map[string]Driver), |
| 123 | tick: time.NewTicker(opts.refreshInterval), |
| 124 | } |
| 125 | download := func() { |
| 126 | err := c.download() |
| 127 | if err != nil { |
| 128 | log.Warnf("unable to download loldrivers.io dataset: %v", err) |
| 129 | } |
| 130 | } |
| 131 | // if async download is enabled we'll |
| 132 | // fetch the initial dataset in a new |
| 133 | // goroutine |
| 134 | if opts.asyncDownload { |
| 135 | go download() |
| 136 | } else { |
| 137 | download() |
| 138 | } |
| 139 | // start refresh goroutine |
| 140 | go c.refresh() |
| 141 | } |
| 142 | return c |
| 143 | } |
| 144 | |
| 145 | const maxDriverSize = 1_000_000 * 100 |
| 146 |
no test coverage detected