bookstore

package
v0.0.0-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

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:

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

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

func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

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

func (c *Client) Close() error

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

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:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL