luci: Index | Files

package internal

import ""


Package Files

fetch.go mergedctx.go testing.go

func RegisterClientFactory Uses

func RegisterClientFactory(f ClientFactory)

RegisterClientFactory allows external module to provide implementation of the ClientFactory.

This is needed to resolve module dependency cycle between server/auth and server/auth/internal.

See init() in server/auth/client.go.

If client factory is not set, Do(...) uses http.DefaultClient. This happens in unit tests for various auth/* subpackages.

func WithTestTransport Uses

func WithTestTransport(c context.Context, cb TestTransportCallback) context.Context

WithTestTransport puts a testing transport in the context to use for fetches.

type ClientFactory Uses

type ClientFactory func(c context.Context, scopes []string) (*http.Client, error)

ClientFactory knows how to produce http.Client that attach proper OAuth headers.

If 'scopes' is empty, the factory should return a client that makes anonymous requests.

type MergedContext Uses

type MergedContext struct {
    Root     context.Context
    Fallback context.Context

MergedContext is a context that inherits everything from Root, except values are additionally inherited from Fallback.

func (*MergedContext) Deadline Uses

func (mc *MergedContext) Deadline() (time.Time, bool)

func (*MergedContext) Done Uses

func (mc *MergedContext) Done() <-chan struct{}

func (*MergedContext) Err Uses

func (mc *MergedContext) Err() error

func (*MergedContext) Value Uses

func (mc *MergedContext) Value(key interface{}) interface{}

type Request Uses

type Request struct {
    Method  string            // HTTP method to use
    URL     string            // URL to access
    Scopes  []string          // OAuth2 scopes to authenticate with or anonymous call if empty
    Headers map[string]string // optional map with request headers
    Body    interface{}       // object to convert to JSON and send as body or []byte with the body
    Out     interface{}       // where to deserialize the response to

Request represents one JSON REST API request.

func (*Request) Do Uses

func (r *Request) Do(c context.Context) error

Do performs an HTTP request with retries on transient errors.

It can be used to make GET or DELETE requests (if Body is nil) or POST or PUT requests (if Body is not nil). In latter case the body will be serialized to JSON.

Respects context's deadline and cancellation.

type TestTransportCallback Uses

type TestTransportCallback func(r *http.Request, body string) (code int, response string)

TestTransportCallback is used from unit tests.

Package internal imports 11 packages (graph) and is imported by 8 packages. Updated 2020-12-06. Refresh now. Tools for package owners.