Documentation ¶
Overview ¶
NOTE: This package is in alpha. It is not stable, and is likely to change.
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.
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 := bookstore.NewClient(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.
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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.CreateBookRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#CreateBookRequest. } resp, err := c.CreateBook(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context ¶
The ctx passed to NewClient 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 CallOptions
- type Client
- func (c *Client) Close() error
- func (c *Client) Connection() *grpc.ClientConndeprecated
- func (c *Client) CreateBook(ctx context.Context, req *bookstorepb.CreateBookRequest, ...) (*bookstorepb.Book, error)
- func (c *Client) CreateShelf(ctx context.Context, req *bookstorepb.CreateShelfRequest, ...) (*bookstorepb.Shelf, error)
- func (c *Client) DeleteBook(ctx context.Context, req *bookstorepb.DeleteBookRequest, ...) error
- func (c *Client) DeleteShelf(ctx context.Context, req *bookstorepb.DeleteShelfRequest, ...) error
- func (c *Client) GetBook(ctx context.Context, req *bookstorepb.GetBookRequest, opts ...gax.CallOption) (*bookstorepb.Book, error)
- func (c *Client) GetShelf(ctx context.Context, req *bookstorepb.GetShelfRequest, opts ...gax.CallOption) (*bookstorepb.Shelf, error)
- func (c *Client) ListBooks(ctx context.Context, req *bookstorepb.ListBooksRequest, opts ...gax.CallOption) (*bookstorepb.ListBooksResponse, error)
- func (c *Client) ListShelves(ctx context.Context, req *emptypb.Empty, opts ...gax.CallOption) (*bookstorepb.ListShelvesResponse, error)
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 CallOptions ¶
type CallOptions struct { ListShelves []gax.CallOption CreateShelf []gax.CallOption GetShelf []gax.CallOption DeleteShelf []gax.CallOption ListBooks []gax.CallOption CreateBook []gax.CallOption GetBook []gax.CallOption DeleteBook []gax.CallOption }
CallOptions contains the retry settings for each method of Client.
type Client ¶
type Client struct { // The call options for this service. CallOptions *CallOptions // contains filtered or unexported fields }
Client is a client for interacting with . Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
A simple Bookstore API.
The API manages shelves and books resources. Shelves contain books.
func NewClient ¶
NewClient creates a new bookstore service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
A simple Bookstore API.
The API manages shelves and books resources. Shelves contain books.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func (*Client) Close ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Connection
deprecated
func (c *Client) 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 (*Client) CreateBook ¶
func (c *Client) CreateBook(ctx context.Context, req *bookstorepb.CreateBookRequest, opts ...gax.CallOption) (*bookstorepb.Book, error)
CreateBook creates a new book.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.CreateBookRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#CreateBookRequest. } resp, err := c.CreateBook(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*Client) CreateShelf ¶
func (c *Client) CreateShelf(ctx context.Context, req *bookstorepb.CreateShelfRequest, opts ...gax.CallOption) (*bookstorepb.Shelf, error)
CreateShelf creates a new shelf in the bookstore.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.CreateShelfRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#CreateShelfRequest. } resp, err := c.CreateShelf(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*Client) DeleteBook ¶
func (c *Client) DeleteBook(ctx context.Context, req *bookstorepb.DeleteBookRequest, opts ...gax.CallOption) error
DeleteBook deletes a book from a shelf.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.DeleteBookRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#DeleteBookRequest. } err = c.DeleteBook(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*Client) DeleteShelf ¶
func (c *Client) DeleteShelf(ctx context.Context, req *bookstorepb.DeleteShelfRequest, opts ...gax.CallOption) error
DeleteShelf deletes a shelf, including all books that are stored on the shelf.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.DeleteShelfRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#DeleteShelfRequest. } err = c.DeleteShelf(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*Client) GetBook ¶
func (c *Client) GetBook(ctx context.Context, req *bookstorepb.GetBookRequest, opts ...gax.CallOption) (*bookstorepb.Book, error)
GetBook returns a specific book.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.GetBookRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#GetBookRequest. } resp, err := c.GetBook(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*Client) GetShelf ¶
func (c *Client) GetShelf(ctx context.Context, req *bookstorepb.GetShelfRequest, opts ...gax.CallOption) (*bookstorepb.Shelf, error)
GetShelf returns a specific bookstore shelf.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.GetShelfRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#GetShelfRequest. } resp, err := c.GetShelf(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*Client) ListBooks ¶
func (c *Client) ListBooks(ctx context.Context, req *bookstorepb.ListBooksRequest, opts ...gax.CallOption) (*bookstorepb.ListBooksResponse, error)
ListBooks returns a list of books on a shelf.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" bookstorepb "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &bookstorepb.ListBooksRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1/bookstorepb#ListBooksRequest. } resp, err := c.ListBooks(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*Client) ListShelves ¶
func (c *Client) ListShelves(ctx context.Context, req *emptypb.Empty, opts ...gax.CallOption) (*bookstorepb.ListShelvesResponse, error)
ListShelves returns a list of all shelves in the bookstore.
Example ¶
package main import ( "context" bookstore "github.com/qclaogui/gaip/genproto/bookstore/apiv1alpha1" emptypb "google.golang.org/protobuf/types/known/emptypb" ) 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 := bookstore.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &emptypb.Empty{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/protobuf/types/known/emptypb#Empty. } resp, err := c.ListShelves(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output: