fix(ftx/rest): add Id() for setting restful id

This commit is contained in:
Jui-Nan Lin 2021-05-24 11:19:30 +08:00
parent 2467d3fcf6
commit 7fd3375741

View File

@ -40,6 +40,9 @@ type restRequest struct {
// payload // payload
p map[string]interface{} p map[string]interface{}
// object id
id string
} }
func newRestRequest(c *http.Client, baseURL *url.URL) *restRequest { func newRestRequest(c *http.Client, baseURL *url.URL) *restRequest {
@ -80,13 +83,23 @@ func (r *restRequest) ReferenceURL(refURL string) *restRequest {
} }
func (r *restRequest) buildURL() (*url.URL, error) { func (r *restRequest) buildURL() (*url.URL, error) {
refURL, err := url.Parse(r.refURL) u := r.refURL
if len(r.id) > 0 {
u = u + "/" + r.id
}
refURL, err := url.Parse(u)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return r.baseURL.ResolveReference(refURL), nil return r.baseURL.ResolveReference(refURL), nil
} }
func (r *restRequest) Id(id string) *restRequest {
r.id = id
return r
}
func (r *restRequest) Payloads(payloads map[string]interface{}) *restRequest { func (r *restRequest) Payloads(payloads map[string]interface{}) *restRequest {
for k, v := range payloads { for k, v := range payloads {
r.p[k] = v r.p[k] = v