init
This commit is contained in:
31
internal/gitadapters/base.go
Normal file
31
internal/gitadapters/base.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package gitadapters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type baseHTTP struct {
|
||||
baseURL string
|
||||
bearerToken string
|
||||
}
|
||||
|
||||
func (b *baseHTTP) createRequest(method string, body io.Reader, path ...string) (r *http.Request, err error) {
|
||||
target, err := url.JoinPath(b.baseURL, path...)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("can not parse path: %w", err)
|
||||
return
|
||||
}
|
||||
req, err := http.NewRequest(method, target, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if b.bearerToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+b.bearerToken)
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
Reference in New Issue
Block a user