go-github
go-github copied to clipboard
Does this package support configuring a proxy?
I want to use this package to au-create the issue in my repo. but my env is private, and we provide a proxy to access the internet. so I am not sure if I can configure a proxy with this package to call my github repo. thanks.
I believe this is possible, but don't have the details. Hopefully others can comment and provide you with what you need. In the meantime, if you figure it out, feel free to report back to this issue with the solution to benefit others. Thanks.
@gmlewis thanks, for now, I have no idea to do it. if I figure it out, I will post it here. thanks.
You need to configure the proxy in a new http.client and pass it as a parameter to your "github client"
package main
import (
"context"
"fmt"
"log"
"github.com/google/go-github/v45/github"
"net/http"
"net/url"
)
func main() {
//creating the proxyURL
proxyStr := "<your-proxy-url>"
proxyURL, err := url.Parse(proxyStr)
if err != nil {
log.Println(err)
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
//adding the Transport object to the http Client
httpclient := &http.Client{
Transport: transport,
}
client := github.NewClient(httpclient)
// list public repositories for org "github"
opt := &github.RepositoryListByOrgOptions{Type: "public"}
repos, _, err := client.Repositories.ListByOrg(context.Background(), "github", opt)
if err != nil {
log.Fatal(err)
}
// If no error was returned, print the returned message
// to the console.
fmt.Println(repos)
}
Thank you, @extravio !
Closing due to solution provided above: https://github.com/google/go-github/issues/2363#issuecomment-1138153077