docs: add documentation comments for apps and paging types

- add doc comments to `AppsEndpoint`, `App` struct, and the `Get` method
in `apps.go`.
- add doc comments to the `Page` struct in `page.go`.
- add doc comments to `PagingRequest`, `PagingOption`, and paging helper
functions in `pagingRequest.go`.
This commit is contained in:
Stevan Freeborn
2026-01-15 17:10:41 -06:00
parent 126b027a81
commit c00998eed6
3 changed files with 17 additions and 0 deletions
+11
View File
@@ -9,16 +9,27 @@ const (
appsPath = "/apps" appsPath = "/apps"
) )
// AppsEndpoint provides access to apps in an Onspring instance.
type AppsEndpoint struct { type AppsEndpoint struct {
client *Client client *Client
} }
// App represents an Onspring app
type App struct { type App struct {
Href string `json:"href"` Href string `json:"href"`
Id int `json:"id"` Id int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
// Get retrieves a paginated list of apps from the Onspring API.
//
// Parameters:
// - ctx: The context for the request
// - pagingOpts: Optional paging configuration functions (e.g., ForPageNumber, WithPageSize)
//
// Returns:
// - Page[App]: A page of apps with pagination metadata
// - error: An error if the request fails
func (p *AppsEndpoint) Get(ctx context.Context, pagingOpts ...PagingOption) (Page[App], error) { func (p *AppsEndpoint) Get(ctx context.Context, pagingOpts ...PagingOption) (Page[App], error) {
pagingRequest := &PagingRequest{ pagingRequest := &PagingRequest{
pageNumber: 1, pageNumber: 1,
+1
View File
@@ -1,5 +1,6 @@
package onspring package onspring
// Page represents a paginated response from the Onspring API.
type Page[T any] struct { type Page[T any] struct {
PageNumber int `json:"pageNumber"` PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"` PageSize int `json:"pageSize"`
+5
View File
@@ -2,11 +2,13 @@ package onspring
import "strconv" import "strconv"
// PagingRequest contains pagination parameters for API requests.
type PagingRequest struct { type PagingRequest struct {
pageNumber int pageNumber int
pageSize int pageSize int
} }
// ToParams converts the paging request to a map of query parameters.
func (pr *PagingRequest) ToParams() map[string]string { func (pr *PagingRequest) ToParams() map[string]string {
return map[string]string{ return map[string]string{
"pageNumber": strconv.Itoa(pr.pageNumber), "pageNumber": strconv.Itoa(pr.pageNumber),
@@ -14,14 +16,17 @@ func (pr *PagingRequest) ToParams() map[string]string {
} }
} }
// PagingOption is a function that modifies a PagingRequest.
type PagingOption func(*PagingRequest) type PagingOption func(*PagingRequest)
// ForPageNumber sets the page number for a paging request.
func ForPageNumber(pageNumber int) PagingOption { func ForPageNumber(pageNumber int) PagingOption {
return func(pr *PagingRequest) { return func(pr *PagingRequest) {
pr.pageNumber = pageNumber pr.pageNumber = pageNumber
} }
} }
// WithPageSize sets the page size for a paging request.
func WithPageSize(pageSize int) PagingOption { func WithPageSize(pageSize int) PagingOption {
return func(pr *PagingRequest) { return func(pr *PagingRequest) {
pr.pageSize = pageSize pr.pageSize = pageSize