library

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: 20 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 := library.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 := library.NewClient(ctx)
if err != nil {
	// TODO: Handle error.
}
defer c.Close()

req := &librarypb.CreateBookRequest{
	// TODO: Fill request struct fields.
	// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#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 BookIterator

type BookIterator 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 []*librarypb.Book, nextPageToken string, err error)
	// contains filtered or unexported fields
}

BookIterator manages a stream of *librarypb.Book.

func (*BookIterator) Next

func (it *BookIterator) Next() (*librarypb.Book, 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 (*BookIterator) PageInfo

func (it *BookIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

type CallOptions

type CallOptions struct {
	CreateShelf  []gax.CallOption
	GetShelf     []gax.CallOption
	ListShelves  []gax.CallOption
	DeleteShelf  []gax.CallOption
	MergeShelves []gax.CallOption
	CreateBook   []gax.CallOption
	GetBook      []gax.CallOption
	ListBooks    []gax.CallOption
	DeleteBook   []gax.CallOption
	UpdateBook   []gax.CallOption
	MoveBook     []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.

This API represents a simple digital library. It lets you manage Shelf resources and Book resources in the library. It defines the following resource model:

The API has a collection of Shelf
resources, named shelves/*

Each Shelf has a collection of Book
resources, named shelves/*/books/*

func NewClient

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

NewClient creates a new library service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.

This API represents a simple digital library. It lets you manage Shelf resources and Book resources in the library. It defines the following resource model:

The API has a collection of Shelf
resources, named shelves/*

Each Shelf has a collection of Book
resources, named shelves/*/books/*
Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}
Output:

func NewRESTClient

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

NewRESTClient creates a new library service rest client.

This API represents a simple digital library. It lets you manage Shelf resources and Book resources in the library. It defines the following resource model:

The API has a collection of Shelf
resources, named shelves/*

Each Shelf has a collection of Book
resources, named shelves/*/books/*
Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/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 := library.NewRESTClient(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 *librarypb.CreateBookRequest, opts ...gax.CallOption) (*librarypb.Book, error)

CreateBook creates a book, and returns the new Book.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.CreateBookRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#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 *librarypb.CreateShelfRequest, opts ...gax.CallOption) (*librarypb.Shelf, error)

CreateShelf creates a shelf, and returns the new Shelf.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.CreateShelfRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#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 *librarypb.DeleteBookRequest, opts ...gax.CallOption) error

DeleteBook deletes a book. Returns NOT_FOUND if the book does not exist.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.DeleteBookRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#DeleteBookRequest.
	}
	err = c.DeleteBook(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
}
Output:

func (*Client) DeleteShelf

func (c *Client) DeleteShelf(ctx context.Context, req *librarypb.DeleteShelfRequest, opts ...gax.CallOption) error

DeleteShelf deletes a shelf. Returns NOT_FOUND if the shelf does not exist.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.DeleteShelfRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#DeleteShelfRequest.
	}
	err = c.DeleteShelf(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
}
Output:

func (*Client) GetBook

func (c *Client) GetBook(ctx context.Context, req *librarypb.GetBookRequest, opts ...gax.CallOption) (*librarypb.Book, error)

GetBook gets a book. Returns NOT_FOUND if the book does not exist.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.GetBookRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#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 *librarypb.GetShelfRequest, opts ...gax.CallOption) (*librarypb.Shelf, error)

GetShelf gets a shelf. Returns NOT_FOUND if the shelf does not exist.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.GetShelfRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#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 *librarypb.ListBooksRequest, opts ...gax.CallOption) *BookIterator

ListBooks lists books in a shelf. The order is unspecified but deterministic. Newly created books will not necessarily be added to the end of this list. Returns NOT_FOUND if the shelf does not exist.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
	"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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.ListBooksRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#ListBooksRequest.
	}
	it := c.ListBooks(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp
	}
}
Output:

func (*Client) ListShelves

func (c *Client) ListShelves(ctx context.Context, req *librarypb.ListShelvesRequest, opts ...gax.CallOption) *ShelfIterator

ListShelves lists shelves. The order is unspecified but deterministic. Newly created shelves will not necessarily be added to the end of this list.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
	"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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.ListShelvesRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#ListShelvesRequest.
	}
	it := c.ListShelves(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp
	}
}
Output:

func (*Client) MergeShelves

func (c *Client) MergeShelves(ctx context.Context, req *librarypb.MergeShelvesRequest, opts ...gax.CallOption) (*librarypb.Shelf, error)

MergeShelves merges two shelves by adding all books from the shelf named other_shelf_name to shelf name, and deletes other_shelf_name. Returns the updated shelf. The book ids of the moved books may not be the same as the original books.

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified shelves are the same.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.MergeShelvesRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#MergeShelvesRequest.
	}
	resp, err := c.MergeShelves(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
Output:

func (*Client) MoveBook

func (c *Client) MoveBook(ctx context.Context, req *librarypb.MoveBookRequest, opts ...gax.CallOption) (*librarypb.Book, error)

MoveBook moves a book to another shelf, and returns the new book. The book id of the new book may not be the same as the original book.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.MoveBookRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#MoveBookRequest.
	}
	resp, err := c.MoveBook(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
Output:

func (*Client) UpdateBook

func (c *Client) UpdateBook(ctx context.Context, req *librarypb.UpdateBookRequest, opts ...gax.CallOption) (*librarypb.Book, error)

UpdateBook updates a book. Returns INVALID_ARGUMENT if the name of the book is non-empty and does not equal the existing name.

Example
package main

import (
	"context"

	library "github.com/qclaogui/gaip/genproto/library/apiv1"
	librarypb "github.com/qclaogui/gaip/genproto/library/apiv1/librarypb"
)

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 := library.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &librarypb.UpdateBookRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/github.com/qclaogui/gaip/genproto/library/apiv1/librarypb#UpdateBookRequest.
	}
	resp, err := c.UpdateBook(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
Output:

type ShelfIterator

type ShelfIterator 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 []*librarypb.Shelf, nextPageToken string, err error)
	// contains filtered or unexported fields
}

ShelfIterator manages a stream of *librarypb.Shelf.

func (*ShelfIterator) Next

func (it *ShelfIterator) Next() (*librarypb.Shelf, 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 (*ShelfIterator) PageInfo

func (it *ShelfIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

Jump to

Keyboard shortcuts

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