Documentation
¶
Overview ¶
Package dkapi provides shared primitives for Google Developer Knowledge API clients.
This module complements (rather than replaces) the official generated client at google.golang.org/api/developerknowledge/v1. It focuses on auth-mode selection, quota-project handling for local ADC, rate-limit retry, batch bisection helpers, and document-name normalization used by dkcli, gcp-docs-mirror-tools, and spanner-mycli.
Authentication supports API keys (DEVELOPERKNOWLEDGE_API_KEY or GOOGLE_API_KEY) and Application Default Credentials. When CLOUDSDK_CONFIG is set, both token and quota-project metadata are read from that directory's ADC file.
Index ¶
- Constants
- func APIKeyFromEnv() string
- func CheckResponse(resp *http.Response) ([]byte, error)
- func DefaultADCCredentialsPath(goos, homeDir, appData string) string
- func DefaultCredentialsPath() string
- func IsBisectableDocumentError(err error) bool
- func NewADCHTTPClient(ctx context.Context, cfg AuthConfig) (*http.Client, error)
- func NewAuthenticatedHTTPClient(ctx context.Context, cfg AuthConfig) (*http.Client, string, error)
- func NormalizeDocName(name string) string
- func ParseRetryAfter(resp *http.Response) time.Duration
- func SleepContext(ctx context.Context, wait time.Duration) error
- type ADCCredentialsMetadata
- type APIError
- type AuthConfig
- type AuthMode
- type BatchGetResponse
- type Client
- func (c *Client) BatchGetDocuments(ctx context.Context, names []string) ([]Document, error)
- func (c *Client) BatchGetDocumentsAll(ctx context.Context, names []string) ([]Document, error)
- func (c *Client) DoAPIRequest(ctx context.Context, method, reqURL string, body []byte, contentType string) ([]byte, error)
- func (c *Client) DoGet(ctx context.Context, reqURL string) ([]byte, error)
- func (c *Client) DoJSONPost(ctx context.Context, reqURL string, body []byte) ([]byte, error)
- type Document
- type DocumentChunk
- type QuotaProjectTransport
- type RateLimitError
- type TokenSourceFunc
- type Waiter
Constants ¶
const ( CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" DefaultV1BaseURL = "https://developerknowledge.googleapis.com/v1" DefaultHTTPTimeout = time.Minute // MaxBatchGetDocuments is the maximum number of document names accepted by // documents:batchGet. Documents are returned in the same order as names. MaxBatchGetDocuments = 20 )
Variables ¶
This section is empty.
Functions ¶
func APIKeyFromEnv ¶
func APIKeyFromEnv() string
func DefaultCredentialsPath ¶
func DefaultCredentialsPath() string
func NewADCHTTPClient ¶
func NormalizeDocName ¶
NormalizeDocName converts a pasted URL or short document path into a Developer Knowledge API resource name (documents/...). Query strings, fragments, and trailing slashes are stripped.
Types ¶
type ADCCredentialsMetadata ¶
type ADCCredentialsMetadata struct {
Type string `json:"type"`
QuotaProjectID string `json:"quota_project_id"`
}
func LoadADCCredentialsMetadata ¶
func LoadADCCredentialsMetadata(credentialsPath func() string) ADCCredentialsMetadata
func ResolveQuotaProjectID ¶
func ResolveQuotaProjectID(credentialsPath func() string) (string, ADCCredentialsMetadata)
type AuthConfig ¶
type AuthConfig struct {
Mode AuthMode
Timeout time.Duration
TokenSource TokenSourceFunc
CredentialsPath func() string
}
type BatchGetResponse ¶
type BatchGetResponse struct {
Documents []Document `json:"documents" yaml:"documents"`
}
type Client ¶
type Client struct {
BaseURL string
APIKey string
HTTPClient *http.Client
Limiter Waiter
Verbose bool
VerboseWriter io.Writer
// MaxRetries is the number of additional attempts after the first request.
MaxRetries int
}
func (*Client) BatchGetDocuments ¶
func (*Client) BatchGetDocumentsAll ¶ added in v0.2.0
BatchGetDocumentsAll fetches documents in chunks of MaxBatchGetDocuments while preserving the order of names. Invalid names fail the whole batch for that chunk.
func (*Client) DoAPIRequest ¶
type Document ¶
type Document struct {
Name string `json:"name" yaml:"name"`
URI string `json:"uri" yaml:"uri"`
Content string `json:"content,omitempty" yaml:"content,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
DataSource string `json:"dataSource,omitempty" yaml:"data_source,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
UpdateTime string `json:"updateTime,omitempty" yaml:"update_time,omitempty"`
View string `json:"view,omitempty" yaml:"view,omitempty"`
ContentLengthBytes int64 `json:"contentLengthBytes,omitempty" yaml:"content_length_bytes,omitempty"`
}
type DocumentChunk ¶
type QuotaProjectTransport ¶
type QuotaProjectTransport struct {
Base http.RoundTripper
Project string
}
type RateLimitError ¶
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type TokenSourceFunc ¶
var DefaultTokenSource TokenSourceFunc = func(ctx context.Context, scopes ...string) (oauth2.TokenSource, error) { return google.DefaultTokenSource(ctx, scopes...) }