forked from microsoftgraph/msgraph-sdk-go-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_client_factory.go
29 lines (25 loc) · 1.02 KB
/
graph_client_factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package msgraphgocore
import (
nethttp "net/http"
khttp "github.com/microsoft/kiota-http-go"
)
// GetDefaultMiddlewaresWithOptions creates a default slice of middleware for the Graph Client.
func GetDefaultMiddlewaresWithOptions(options *GraphClientOptions) []khttp.Middleware {
kiotaMiddlewares := khttp.GetDefaultMiddlewares()
graphMiddlewares := []khttp.Middleware{
NewGraphTelemetryHandler(options),
khttp.NewUrlReplaceHandler(),
}
graphMiddlewaresLen := len(graphMiddlewares)
resultMiddlewares := make([]khttp.Middleware, len(kiotaMiddlewares)+graphMiddlewaresLen)
copy(resultMiddlewares, graphMiddlewares)
copy(resultMiddlewares[graphMiddlewaresLen:], kiotaMiddlewares)
return resultMiddlewares
}
// GetDefaultClient creates a new http client with a preconfigured middleware pipeline
func GetDefaultClient(options *GraphClientOptions, middleware ...khttp.Middleware) *nethttp.Client {
if len(middleware) == 0 {
middleware = GetDefaultMiddlewaresWithOptions(options)
}
return khttp.GetDefaultClient(middleware...)
}