mirror of
https://github.com/packwiz/packwiz.git
synced 2025-05-11 22:56:30 +02:00
github: Accept GitHub API token via OS environment variable
"GH_API_TOKEN" Signed-off-by: unilock <unilock@fennet.rentals>
This commit is contained in:
parent
c96a6a30ad
commit
8d4f8d9a86
@ -3,6 +3,7 @@ package github
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/packwiz/packwiz/core"
|
"github.com/packwiz/packwiz/core"
|
||||||
)
|
)
|
||||||
@ -17,6 +18,8 @@ type ghApiClient struct {
|
|||||||
var ghDefaultClient = ghApiClient{&http.Client{}}
|
var ghDefaultClient = ghApiClient{&http.Client{}}
|
||||||
|
|
||||||
func (c *ghApiClient) makeGet(url string) (*http.Response, error) {
|
func (c *ghApiClient) makeGet(url string) (*http.Response, error) {
|
||||||
|
ghApiToken := os.Getenv("GH_API_TOKEN")
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -24,6 +27,9 @@ func (c *ghApiClient) makeGet(url string) (*http.Response, error) {
|
|||||||
|
|
||||||
req.Header.Set("User-Agent", core.UserAgent)
|
req.Header.Set("User-Agent", core.UserAgent)
|
||||||
req.Header.Set("Accept", "application/vnd.github+json")
|
req.Header.Set("Accept", "application/vnd.github+json")
|
||||||
|
if ghApiToken != "" {
|
||||||
|
req.Header.Set("Authorization", "Bearer " + ghApiToken)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user