Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this package support configuring a proxy? #2363

Closed
songleo opened this issue May 11, 2022 · 4 comments
Closed

Does this package support configuring a proxy? #2363

songleo opened this issue May 11, 2022 · 4 comments

Comments

@songleo
Copy link

songleo commented May 11, 2022

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.

@gmlewis
Copy link
Collaborator

gmlewis commented May 11, 2022

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.

@songleo
Copy link
Author

songleo commented May 11, 2022

@gmlewis thanks, for now, I have no idea to do it. if I figure it out, I will post it here. thanks.

@extravio
Copy link

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)
}

@gmlewis
Copy link
Collaborator

gmlewis commented Mar 8, 2023

Thank you, @extravio !

Closing due to solution provided above: #2363 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants