-
Notifications
You must be signed in to change notification settings - Fork 501
/
asset_request.go
40 lines (33 loc) · 993 Bytes
/
asset_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package horizonclient
import (
"fmt"
"net/http"
"net/url"
"github.com/stellar/go/support/errors"
)
// BuildURL creates the endpoint to be queried based on the data in the AssetRequest struct.
// If no data is set, it defaults to the build the URL for all assets
func (ar AssetRequest) BuildURL() (endpoint string, err error) {
endpoint = "assets"
queryParams := addQueryParams(assetCode(ar.ForAssetCode), assetIssuer(ar.ForAssetIssuer), cursor(ar.Cursor), limit(ar.Limit), ar.Order)
if queryParams != "" {
endpoint = fmt.Sprintf(
"%s?%s",
endpoint,
queryParams,
)
}
_, err = url.Parse(endpoint)
if err != nil {
err = errors.Wrap(err, "failed to parse endpoint")
}
return endpoint, err
}
// HTTPRequest returns the http request for the assets endpoint
func (ar AssetRequest) HTTPRequest(horizonURL string) (*http.Request, error) {
endpoint, err := ar.BuildURL()
if err != nil {
return nil, err
}
return http.NewRequest("GET", horizonURL+endpoint, nil)
}