github.com/blend/go-sdk@v1.20220411.3/pagerduty/http_client.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package pagerduty 9 10 import ( 11 "context" 12 "fmt" 13 "net/http" 14 15 "github.com/blend/go-sdk/r2" 16 "github.com/blend/go-sdk/webutil" 17 ) 18 19 var ( 20 _ Client = (*HTTPClient)(nil) 21 ) 22 23 // HTTPClient is an implementation of the http client. 24 type HTTPClient struct { 25 Config Config 26 Defaults []r2.Option 27 } 28 29 // Request creates a request with a context and a given set of options. 30 func (hc HTTPClient) Request(ctx context.Context, opts ...r2.Option) *r2.Request { 31 callOptions := []r2.Option{ 32 r2.OptContext(ctx), 33 r2.OptHeaderValue(webutil.HeaderContentType, webutil.ContentTypeApplicationJSON), 34 r2.OptHeaderValue(webutil.HeaderAccept, "application/vnd.pagerduty+json;version=2"), 35 r2.OptHeaderValue(webutil.HeaderAuthorization, fmt.Sprintf("Token token=%s", hc.Config.Token)), 36 } 37 if hc.Config.Email != "" { 38 callOptions = append(callOptions, 39 r2.OptHeaderValue(http.CanonicalHeaderKey("From"), hc.Config.Email), 40 ) 41 } 42 baseOptions := append(hc.Defaults, 43 callOptions..., 44 ) 45 return r2.New(hc.Config.Addr, append(baseOptions, opts...)...) 46 }