go: firebase.google.com/go/internal Index | Files

package internal

import "firebase.google.com/go/internal"

Package internal contains functionality that is only accessible from within the Admin SDK.


Package Files

http_client.go internal.go


var FirebaseScopes = []string{

FirebaseScopes is the set of OAuth2 scopes used by the Admin SDK.

var SystemClock = &systemClock{}

SystemClock is a clock that returns local time of the system.

func HasErrorCode Uses

func HasErrorCode(err error, code string) bool

HasErrorCode checks if the given error contain a specific error code.

type AuthConfig Uses

type AuthConfig struct {
    Opts             []option.ClientOption
    Creds            *google.DefaultCredentials
    ProjectID        string
    ServiceAccountID string
    Version          string

AuthConfig represents the configuration of Firebase Auth service.

type Clock Uses

type Clock interface {
    Now() time.Time

Clock is used to query the current local time.

type DatabaseConfig Uses

type DatabaseConfig struct {
    Opts         []option.ClientOption
    URL          string
    Version      string
    AuthOverride map[string]interface{}

DatabaseConfig represents the configuration of Firebase Database service.

type ErrorParser Uses

type ErrorParser func([]byte) string

ErrorParser is a function that is used to construct custom error messages.

type FirebaseError Uses

type FirebaseError struct {
    Code   string
    String string

FirebaseError is an error type containing an error code string.

func Error Uses

func Error(code string, msg string) *FirebaseError

Error creates a new FirebaseError from the specified error code and message.

func Errorf Uses

func Errorf(code string, msg string, args ...interface{}) *FirebaseError

Errorf creates a new FirebaseError from the specified error code and message.

func (*FirebaseError) Error Uses

func (fe *FirebaseError) Error() string

type HTTPClient Uses

type HTTPClient struct {
    Client      *http.Client
    RetryConfig *RetryConfig
    ErrParser   ErrorParser

HTTPClient is a convenient API to make HTTP calls.

This API handles repetitive tasks such as entity serialization and deserialization when making HTTP calls. It provides a convenient mechanism to set headers and query parameters on outgoing requests, while enforcing that an explicit context is used per request. Responses returned by HTTPClient can be easily unmarshalled as JSON.

HTTPClient also handles automatically retrying failed HTTP requests.

func NewHTTPClient Uses

func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*HTTPClient, string, error)

NewHTTPClient creates a new HTTPClient using the provided client options and the default RetryConfig.

The default RetryConfig retries requests on all low-level network errors as well as on HTTP InternalServerError (500) and ServiceUnavailable (503) errors. Repeatedly failing requests are retried up to 4 times with exponential backoff. Retry delay is never longer than 2 minutes.

NewHTTPClient returns the created HTTPClient along with the target endpoint URL. The endpoint is obtained from the client options passed into the function.

func (*HTTPClient) Do Uses

func (c *HTTPClient) Do(ctx context.Context, req *Request) (*Response, error)

Do executes the given Request, and returns a Response.

If a RetryConfig is specified on the client, Do attempts to retry failing requests.

type HTTPEntity Uses

type HTTPEntity interface {
    Bytes() ([]byte, error)
    Mime() string

HTTPEntity represents a payload that can be included in an outgoing HTTP request.

func NewJSONEntity Uses

func NewJSONEntity(v interface{}) HTTPEntity

NewJSONEntity creates a new HTTPEntity that will be serialized into JSON.

type HTTPOption Uses

type HTTPOption func(*http.Request)

HTTPOption is an additional parameter that can be specified to customize an outgoing request.

func WithHeader Uses

func WithHeader(key, value string) HTTPOption

WithHeader creates an HTTPOption that will set an HTTP header on the request.

func WithQueryParam Uses

func WithQueryParam(key, value string) HTTPOption

WithQueryParam creates an HTTPOption that will set a query parameter on the request.

func WithQueryParams Uses

func WithQueryParams(qp map[string]string) HTTPOption

WithQueryParams creates an HTTPOption that will set all the entries of qp as query parameters on the request.

type HashConfig Uses

type HashConfig map[string]interface{}

HashConfig represents a hash algorithm configuration used to generate password hashes.

type InstanceIDConfig Uses

type InstanceIDConfig struct {
    Opts      []option.ClientOption
    ProjectID string

InstanceIDConfig represents the configuration of Firebase Instance ID service.

type MessagingConfig Uses

type MessagingConfig struct {
    Opts      []option.ClientOption
    ProjectID string
    Version   string

MessagingConfig represents the configuration of Firebase Cloud Messaging service.

type MockClock Uses

type MockClock struct {
    Timestamp time.Time

MockClock can be used to mock current time during tests.

func (*MockClock) Now Uses

func (m *MockClock) Now() time.Time

Now returns the timestamp set in the MockClock.

type MockTokenSource Uses

type MockTokenSource struct {
    AccessToken string

MockTokenSource is a TokenSource implementation that can be used for testing.

func (*MockTokenSource) Token Uses

func (ts *MockTokenSource) Token() (*oauth2.Token, error)

Token returns the test token associated with the TokenSource.

type Request Uses

type Request struct {
    Method string
    URL    string
    Body   HTTPEntity
    Opts   []HTTPOption

Request contains all the parameters required to construct an outgoing HTTP request.

type Response Uses

type Response struct {
    Status int
    Header http.Header
    Body   []byte
    // contains filtered or unexported fields

Response contains information extracted from an HTTP response.

func (*Response) CheckStatus Uses

func (r *Response) CheckStatus(want int) error

CheckStatus checks whether the Response status code has the given HTTP status code.

Returns an error if the status code does not match. If an ErrorParser is specified, uses that to construct the returned error message. Otherwise includes the full response body in the error.

func (*Response) Unmarshal Uses

func (r *Response) Unmarshal(want int, v interface{}) error

Unmarshal checks if the Response has the given HTTP status code, and if so unmarshals the response body into the variable pointed by v.

Unmarshal uses https://golang.org/pkg/encoding/json/#Unmarshal internally, and hence v has the same requirements as the json package.

type RetryCondition Uses

type RetryCondition func(resp *http.Response, networkErr error) bool

RetryCondition determines if an HTTP request should be retried depending on its last outcome.

type RetryConfig Uses

type RetryConfig struct {
    MaxRetries       int
    CheckForRetry    RetryCondition
    ExpBackoffFactor float64
    MaxDelay         *time.Duration

RetryConfig specifies how the HTTPClient should retry failing HTTP requests.

A request is never retried more than MaxRetries times. If CheckForRetry is nil, all network errors, and all 400+ HTTP status codes are retried. If an HTTP error response contains the Retry-After header, it is always respected. Otherwise retries are delayed with exponential backoff. Set ExpBackoffFactor to 0 to disable exponential backoff, and retry immediately after each error.

If MaxDelay is set, retries delay gets capped by that value. If the Retry-After header requires a longer delay than MaxDelay, retries are not attempted.

type StorageConfig Uses

type StorageConfig struct {
    Opts   []option.ClientOption
    Bucket string

StorageConfig represents the configuration of Google Cloud Storage service.

Package internal imports 14 packages (graph) and is imported by 6 packages. Updated 2019-07-01. Refresh now. Tools for package owners.