|
1 | | -# aep-go |
| 1 | +# AEP Go |
| 2 | + |
| 3 | +Go SDK implementation of [API Extension Proposals](https://aep.dev/) |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project contains a collection of helper functions to make it easier to adopt |
| 8 | +AEP. It also contains a code generator that can be used together with Protool Buffers, |
| 9 | +to make the proces even simpler |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +go get github.com/blaberg/aep-go |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +### List functionality |
| 20 | + |
| 21 | +```go |
| 22 | +func (s *Service) ListBooks(ctx context.Context, req *bookv1.ListBooksRequest) (*bookv1.ListBooksResponse, error) { |
| 23 | + // Validate parent format |
| 24 | + _, err := resourcepath.ParseString(req.Parent, "publishers/{publisher}") |
| 25 | + if err != nil { |
| 26 | + return nil, status.Errorf(codes.InvalidArgument, "invalid parent format: %v", err) |
| 27 | + } |
| 28 | + |
| 29 | + // Parse the page token |
| 30 | + token, err := s.paginator.ParsePageToken(req) |
| 31 | + if err != nil { |
| 32 | + return nil, status.Errorf(codes.InvalidArgument, "invalid page token: %v", err) |
| 33 | + } |
| 34 | + |
| 35 | + // Get books with pagination |
| 36 | + books, hasMore := s.storage.List(req.Parent, token.Offset, req.MaxPageSize) |
| 37 | + if books == nil { |
| 38 | + return &bookv1.ListBooksResponse{ |
| 39 | + Results: []*bookv1.Book{}, |
| 40 | + NextPageToken: "", |
| 41 | + }, nil |
| 42 | + } |
| 43 | + |
| 44 | + // Generate the next page token |
| 45 | + nextToken := token.Next(hasMore, req.MaxPageSize) |
| 46 | + nextPageToken := "" |
| 47 | + if nextToken != nil { |
| 48 | + nextPageToken = nextToken.String() |
| 49 | + } |
| 50 | + |
| 51 | + return &bookv1.ListBooksResponse{ |
| 52 | + Results: books, |
| 53 | + NextPageToken: nextPageToken, |
| 54 | + }, nil |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Contributing |
| 59 | + |
| 60 | +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests. |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +This project is licensed under the [LICENSE NAME] - see the [LICENSE](LICENSE) file for details. |
| 65 | + |
| 66 | +## Security |
| 67 | + |
| 68 | +Please report any security issues to [SECURITY.md](SECURITY.md). |
0 commit comments