-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiResponse.go
More file actions
24 lines (21 loc) · 927 Bytes
/
apiResponse.go
File metadata and controls
24 lines (21 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Package https provides utilities and structures for handling
// API requests and responses using the HTTP protocol.
// Copyright (c) APIMatic. All rights reserved.
package https
import "net/http"
// ApiResponse is a generic struct that represents an API response containing data and the HTTP response.
// The `Data` field holds the data of any type `T` returned by the API.
// The `Response` field contains the underlying HTTP response associated with the API call.
type ApiResponse[T any] struct {
Data T `json:"data"`
Response *http.Response `json:"response"`
}
// NewApiResponse creates a new instance of ApiResponse.
// It takes the `data` of type `T` and the `response` as parameters, and returns an ApiResponse[T] struct.
func NewApiResponse[T any](data T, response *http.Response) ApiResponse[T] {
apiResponse := ApiResponse[T]{
Data: data,
Response: response,
}
return apiResponse
}