@@ -15,51 +15,55 @@ $ go get github.com/snyk/code-client-go
1515
1616Use the HTTP client to make HTTP requests with configured retriable codes and authorisation headers for Snyk Rest APIs.
1717
18- Implement the ` github.com/snyk/code- client-go/http.Config ` interface to configure the Snyk Code API client from applications .
18+ You can either configure the client using the functional options pattern provided or by implementing the interfaces .
1919
20- Provide a net/http.Client factory to customize the underlying HTTP protocol behavior (timeouts, etc).
20+ Provide a ` net/http.Client ` factory to customize the underlying HTTP protocol behavior (timeouts, etc).
2121
2222``` go
2323import (
2424 " net/http"
2525
2626 " github.com/rs/zerolog"
27- codehttp " github.com/snyk/code-client-go/http"
27+ codeClientHTTP " github.com/snyk/code-client-go/http"
28+ codeClientObservability " github.com/snyk/code-client-go/observability"
2829)
2930
3031logger := zerlog.NewLogger (...)
31- config := newConfigForMyApp ()
32- httpClient := codehttp.NewHTTPClient (logger, config, func () *http.Client { return http.DefaultClient }, codeInstrumentor, codeErrorReporter)
32+ instrumentor := codeClientObservability.NewInstrumentor ()
33+ errorReporter := codeClientObservability.NewErrorReporter ()
34+ httpClient := codeClientHTTP.NewHTTPClient (
35+ func () *http .Client {
36+ return &http.Client {
37+ Timeout: time.Duration (1 ) * time.Second ,
38+ }
39+ },
40+ codeClientHTTP.WithRetryCount (1 ),
41+ codeClientHTTP.WithLogger (logger),
42+ codeClientHTTP.WithInstrumentor (instrumentor),
43+ codeClientHTTP.WithErrorReporter (errorReporter),
44+ )
3345```
3446
35- The HTTP client exposes a ` DoCall ` function.
47+ The HTTP client exposes a ` Do ` function.
3648
3749### Configuration
3850
39- Implement the ` http .Config` interface to configure the Snyk Code API client from applications.
51+ Implement the ` config .Config` interface to configure the Snyk Code API client from applications.
4052
4153### Code Scanner
4254
4355Use the Code Scanner to trigger a scan for a Snyk Code workspace using the Bundle Manager created above.
56+
4457The Code Scanner exposes a ` UploadAndAnalyze ` function, which can be used like this:
4558
4659``` go
47- import (
48- " net/http"
49-
50- " github.com/rs/zerolog"
51- code " github.com/snyk/code-client-go"
52- )
53-
54- logger := zerlog.NewLogger (...)
5560config := newConfigForMyApp ()
56-
5761codeScanner := code.NewCodeScanner (
5862 httpClient,
59- config,
60- codeInstrumentor,
61- codeErrorReporter ,
62- logger ,
63+ config,
64+ codeClientHTTP. WithLogger (logger),
65+ codeClientHTTP. WithInstrumentor (instrumentor) ,
66+ codeClientHTTP. WithErrorReporter (errorReporter) ,
6367)
6468code.UploadAndAnalyze (context.Background (), requestId, " path/to/workspace" , channelForWalkingFiles, changedFiles)
6569```
0 commit comments