Documentation
¶
Overview ¶
Package knowledge is an auto-generated package for the Developer Knowledge API.
The Developer Knowledge API provides access to Google’s developer knowledge.
NOTE: This package is in beta. It is not stable, and may be subject to changes.
General documentation ¶
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage ¶
To get started with this package, create a client.
// go get cloud.google.com/go/developerknowledge/apiv1@latest
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client ¶
The following is an example of making an API call with the newly created client, mentioned above.
req := &developerknowledgepb.AnswerQueryRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#AnswerQueryRequest.
}
resp, err := c.AnswerQuery(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
Use of Context ¶
The ctx passed to NewDeveloperKnowledgeClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Index ¶
- func DefaultAuthScopes() []string
- type DeveloperKnowledgeCallOptions
- type DeveloperKnowledgeClient
- func (c *DeveloperKnowledgeClient) AnswerQuery(ctx context.Context, req *developerknowledgepb.AnswerQueryRequest, ...) (*developerknowledgepb.AnswerQueryResponse, error)
- func (c *DeveloperKnowledgeClient) BatchGetDocuments(ctx context.Context, req *developerknowledgepb.BatchGetDocumentsRequest, ...) (*developerknowledgepb.BatchGetDocumentsResponse, error)
- func (c *DeveloperKnowledgeClient) Close() error
- func (c *DeveloperKnowledgeClient) Connection() *grpc.ClientConndeprecated
- func (c *DeveloperKnowledgeClient) GetDocument(ctx context.Context, req *developerknowledgepb.GetDocumentRequest, ...) (*developerknowledgepb.Document, error)
- func (c *DeveloperKnowledgeClient) SearchDocumentChunks(ctx context.Context, req *developerknowledgepb.SearchDocumentChunksRequest, ...) *DocumentChunkIterator
- type DocumentChunkIterator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type DeveloperKnowledgeCallOptions ¶
type DeveloperKnowledgeCallOptions struct {
SearchDocumentChunks []gax.CallOption
GetDocument []gax.CallOption
BatchGetDocuments []gax.CallOption
AnswerQuery []gax.CallOption
}
DeveloperKnowledgeCallOptions contains the retry settings for each method of DeveloperKnowledgeClient.
type DeveloperKnowledgeClient ¶
type DeveloperKnowledgeClient struct {
// The call options for this service.
CallOptions *DeveloperKnowledgeCallOptions
// contains filtered or unexported fields
}
DeveloperKnowledgeClient is a client for interacting with Developer Knowledge API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
The Developer Knowledge API provides programmatic access to Google’s public developer documentation, enabling you to integrate this knowledge base into your own applications and workflows.
The API is designed to be the canonical source for machine-readable access to Google’s developer documentation.
A typical use case is to first use DeveloperKnowledge.SearchDocumentChunks to find relevant page URIs based on a query, and then use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments to fetch the full content of the top results.
All document content is provided in Markdown format.
func NewDeveloperKnowledgeClient ¶
func NewDeveloperKnowledgeClient(ctx context.Context, opts ...option.ClientOption) (*DeveloperKnowledgeClient, error)
NewDeveloperKnowledgeClient creates a new developer knowledge client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
The Developer Knowledge API provides programmatic access to Google’s public developer documentation, enabling you to integrate this knowledge base into your own applications and workflows.
The API is designed to be the canonical source for machine-readable access to Google’s developer documentation.
A typical use case is to first use DeveloperKnowledge.SearchDocumentChunks to find relevant page URIs based on a query, and then use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments to fetch the full content of the top results.
All document content is provided in Markdown format.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
Output:
func NewDeveloperKnowledgeRESTClient ¶
func NewDeveloperKnowledgeRESTClient(ctx context.Context, opts ...option.ClientOption) (*DeveloperKnowledgeClient, error)
NewDeveloperKnowledgeRESTClient creates a new developer knowledge rest client.
The Developer Knowledge API provides programmatic access to Google’s public developer documentation, enabling you to integrate this knowledge base into your own applications and workflows.
The API is designed to be the canonical source for machine-readable access to Google’s developer documentation.
A typical use case is to first use DeveloperKnowledge.SearchDocumentChunks to find relevant page URIs based on a query, and then use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments to fetch the full content of the top results.
All document content is provided in Markdown format.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
Output:
func (*DeveloperKnowledgeClient) AnswerQuery ¶
func (c *DeveloperKnowledgeClient) AnswerQuery(ctx context.Context, req *developerknowledgepb.AnswerQueryRequest, opts ...gax.CallOption) (*developerknowledgepb.AnswerQueryResponse, error)
AnswerQuery answers a query using grounded generation.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
developerknowledgepb "cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &developerknowledgepb.AnswerQueryRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#AnswerQueryRequest.
}
resp, err := c.AnswerQuery(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
Output:
func (*DeveloperKnowledgeClient) BatchGetDocuments ¶
func (c *DeveloperKnowledgeClient) BatchGetDocuments(ctx context.Context, req *developerknowledgepb.BatchGetDocumentsRequest, opts ...gax.CallOption) (*developerknowledgepb.BatchGetDocumentsResponse, error)
BatchGetDocuments retrieves multiple documents, each with its full Markdown content.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
developerknowledgepb "cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &developerknowledgepb.BatchGetDocumentsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#BatchGetDocumentsRequest.
}
resp, err := c.BatchGetDocuments(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
Output:
func (*DeveloperKnowledgeClient) Close ¶
func (c *DeveloperKnowledgeClient) Close() error
Close closes the connection to the API service. **Always** call Close() when the client is no longer required.
func (*DeveloperKnowledgeClient) Connection
deprecated
func (c *DeveloperKnowledgeClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*DeveloperKnowledgeClient) GetDocument ¶
func (c *DeveloperKnowledgeClient) GetDocument(ctx context.Context, req *developerknowledgepb.GetDocumentRequest, opts ...gax.CallOption) (*developerknowledgepb.Document, error)
GetDocument retrieves a single document with its full Markdown content.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
developerknowledgepb "cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &developerknowledgepb.GetDocumentRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#GetDocumentRequest.
}
resp, err := c.GetDocument(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
Output:
func (*DeveloperKnowledgeClient) SearchDocumentChunks ¶
func (c *DeveloperKnowledgeClient) SearchDocumentChunks(ctx context.Context, req *developerknowledgepb.SearchDocumentChunksRequest, opts ...gax.CallOption) *DocumentChunkIterator
SearchDocumentChunks searches for developer knowledge across Google’s developer documentation. Returns DocumentChunks based on the user’s query. There may be many chunks from the same Document. To retrieve full documents, use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments with the DocumentChunk.parent returned in the SearchDocumentChunksResponse.results.
Example ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
developerknowledgepb "cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &developerknowledgepb.SearchDocumentChunksRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#SearchDocumentChunksRequest.
}
it := c.SearchDocumentChunks(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*developerknowledgepb.SearchDocumentChunksResponse)
}
}
Output:
Example (All) ¶
package main
import (
"context"
knowledge "cloud.google.com/go/developerknowledge/apiv1"
developerknowledgepb "cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := knowledge.NewDeveloperKnowledgeClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &developerknowledgepb.SearchDocumentChunksRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/developerknowledge/apiv1/developerknowledgepb#SearchDocumentChunksRequest.
}
for resp, err := range c.SearchDocumentChunks(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
Output:
type DocumentChunkIterator ¶
type DocumentChunkIterator struct {
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response interface{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*developerknowledgepb.DocumentChunk, nextPageToken string, err error)
// contains filtered or unexported fields
}
DocumentChunkIterator manages a stream of *developerknowledgepb.DocumentChunk.
func (*DocumentChunkIterator) All ¶
func (it *DocumentChunkIterator) All() iter.Seq2[*developerknowledgepb.DocumentChunk, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*DocumentChunkIterator) Next ¶
func (it *DocumentChunkIterator) Next() (*developerknowledgepb.DocumentChunk, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DocumentChunkIterator) PageInfo ¶
func (it *DocumentChunkIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.