23 lines
418 B
Go
23 lines
418 B
Go
|
|
package ctl
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
)
|
||
|
|
|
||
|
|
type headerTransport struct {
|
||
|
|
tripper http.RoundTripper
|
||
|
|
apiKey string
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewTransport(tripper http.RoundTripper, apiKey string) *headerTransport {
|
||
|
|
return &headerTransport{
|
||
|
|
tripper: tripper,
|
||
|
|
apiKey: apiKey,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (t *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||
|
|
req.Header.Set("X-Api-Key", t.apiKey)
|
||
|
|
return t.tripper.RoundTrip(req)
|
||
|
|
}
|