Repository navigation
Refactor and modernize API - #5
Merged
Merged
Conversation
Close response body on non-200 error paths to prevent resource leaks. Wrap errors with the original error using %w for better debugging.
Fix constant name networkInternetExchangeLANNamepsace typo, fix NewAPIWithAPIKey doc comment, remove unreachable ErrBuildingURL check.
The carrier_count field exists in the API schema but was missing from the struct.
Replace the anonymous struct repeated in every entity with a shared SocialMedia type defined in api.go.
Replace four constructors with a single NewAPI(opts...) using functional options (WithURL, WithAPIKey, WithHTTPClient). Store http.Client on the API struct for connection pooling and configurable timeouts.
Replace per-entity Resource structs, getResource methods, and repetitive Get/GetAll/GetByID functions with generic fetch[T] and fetchByID[T] helpers. All public methods now accept context.Context for cancellation and url.Values for type-safe query parameters, and return []T instead of *[]T. Tests rewritten with httptest to avoid live API calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change: all public API methods now require a
context.Contextas the first parameter and useurl.Valuesinstead ofmap[string]interface{}for search. The constructor is nowNewAPI(opts ...Option).deferNetworkContact.Networkfield tag, unusedErrReadingBody)CarrierCountfield to FacilitySocialMediaas a named type instead of an anonymous struct repeated across entitiesNewAPI,NewAPIWithAPIKey,NewAPIFromURL,NewAPIFromURLWithAPIKey) with a singleNewAPI(opts ...Option)using functional options (WithURL,WithAPIKey,WithHTTPClient)http.Clientacross requests for connection pooling instead of creating one per callfetch[T]andfetchByID[T]helperscontext.Contextto all API methods for cancellation and timeout supportmap[string]interface{}search parameters withurl.Valuesfor type safety — also fixes GET of multiple objets at the same time - PeeringDB API rate limiting #4 (bulk queries likeid__in=1,2,3now work correctly)[]Tinstead of*[]T%wfor propererrors.Is/errors.Assupportnet/http/httptestwith no live API dependency