Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ListShelvesQuery ¶
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)
Click to show internal directories.
Click to hide internal directories.