examplelibrary

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListShelvesQuery

type ListShelvesQuery struct {
	Offset   int64
	PageSize int32
}

type ListShelvesResult

type ListShelvesResult struct {
	Shelves     []*library.Shelf
	HasNextPage bool
}

type Server

type Server struct {
	library.UnimplementedLibraryServiceServer
	Storage *Storage
}

func (*Server) ListShelves

func (s *Server) ListShelves(
	ctx context.Context,
	request *library.ListShelvesRequest,
) (*library.ListShelvesResponse, error)
Example
ctx := context.Background()
server := &Server{
	Storage: &Storage{
		Shelves: []*library.Shelf{
			{Name: "shelves/0001", Theme: "Sci-Fi"},
			{Name: "shelves/0002", Theme: "Horror"},
			{Name: "shelves/0003", Theme: "Romance"},
		},
	},
}
page1, err := server.ListShelves(ctx, &library.ListShelvesRequest{
	PageSize: 2,
})
if err != nil {
	panic(err) // TODO: Handle errors.
}
for _, shelf := range page1.Shelves {
	fmt.Println(shelf.Name, shelf.Theme)
}
fmt.Println(page1.NextPageToken)
page2, err := server.ListShelves(ctx, &library.ListShelvesRequest{
	PageSize:  2,
	PageToken: page1.NextPageToken,
})
if err != nil {
	panic(err) // TODO: Handle errors.
}
for _, shelf := range page2.Shelves {
	fmt.Println(shelf.Name, shelf.Theme)
}
fmt.Println(page2.NextPageToken)
Output:

shelves/0001 Sci-Fi
shelves/0002 Horror
ZXhhbXBsZS5saWJyYXJ5Lkxpc3RTaGVsdmVzMg==
shelves/0003 Romance

type Storage

type Storage struct {
	Shelves []*library.Shelf
}

func (*Storage) ListShelves

func (s *Storage) ListShelves(_ context.Context, query *ListShelvesQuery) (*ListShelvesResult, error)

Jump to

Keyboard shortcuts

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