Documentation ¶
Overview ¶
Package httpclient contains issues.Service implementation over HTTP.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewIssues ¶
NewIssues creates a client that implements issues.Service remotely over HTTP. If a nil httpClient is provided, http.DefaultClient will be used. scheme and host can be empty strings to target local service. A trailing "/" is added to path if there isn't one.
Example ¶
package main import ( "net/http" "net/http/httptest" "github.com/shurcooL/home/internal/exp/service/issue/httpclient" ) func main() { issuesClient := httpclient.NewIssues(nil, "http", "localhost:8080", "/api/issue") // Now you can use any of issuesClient methods. _ = issuesClient } func init() { http.DefaultTransport.(*http.Transport).RegisterProtocol("", localRoundTripper{}) } // localRoundTripper is an http.RoundTripper that executes HTTP transactions // by using http.DefaultServeMux directly, instead of going over an HTTP connection. type localRoundTripper struct{} func (localRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { w := httptest.NewRecorder() http.DefaultServeMux.ServeHTTP(w, req) return w.Result(), nil }
Output:
Example (Authenticated) ¶
package main import ( "context" "net/http" "net/http/httptest" "github.com/shurcooL/home/internal/exp/service/issue/httpclient" "golang.org/x/oauth2" ) func main() { // HTTP client with authentication. src := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "... your access token ..."}, ) httpClient := oauth2.NewClient(context.Background(), src) issuesClient := httpclient.NewIssues(httpClient, "http", "localhost:8080", "/api/issue") // Now you can use any of issuesClient methods. _ = issuesClient } func init() { http.DefaultTransport.(*http.Transport).RegisterProtocol("", localRoundTripper{}) } // localRoundTripper is an http.RoundTripper that executes HTTP transactions // by using http.DefaultServeMux directly, instead of going over an HTTP connection. type localRoundTripper struct{} func (localRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { w := httptest.NewRecorder() http.DefaultServeMux.ServeHTTP(w, req) return w.Result(), nil }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.