MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / initClient

Function initClient

pkg/util/loldrivers/client.go:106–143  ·  view source on GitHub ↗
(options ...Option)

Source from the content-addressed store, hash-verified

104}
105
106func 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
145const maxDriverSize = 1_000_000 * 100
146

Callers 2

InitClientFunction · 0.85
GetClientFunction · 0.85

Calls 2

downloadMethod · 0.80
refreshMethod · 0.80

Tested by

no test coverage detected