| 132 | } |
| 133 | |
| 134 | func (d *Open123) Request(endpoint string, method string, setup func(*resty.Request), result any) (*resty.Response, error) { |
| 135 | client := resty.New() |
| 136 | token, err := d.tm.getToken() |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | req := client.R(). |
| 142 | SetHeader("Authorization", "Bearer "+token). |
| 143 | SetHeader("Platform", "open_platform"). |
| 144 | SetHeader("Content-Type", "application/json"). |
| 145 | SetResult(result) |
| 146 | |
| 147 | if setup != nil { |
| 148 | setup(req) |
| 149 | } |
| 150 | |
| 151 | switch method { |
| 152 | case http.MethodGet: |
| 153 | return req.Get(ApiBaseURL + endpoint) |
| 154 | case http.MethodPost: |
| 155 | return req.Post(ApiBaseURL + endpoint) |
| 156 | case http.MethodPut: |
| 157 | return req.Put(ApiBaseURL + endpoint) |
| 158 | default: |
| 159 | return nil, fmt.Errorf("unsupported method: %s", method) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | func (d *Open123) RequestTo(fullURL string, method string, setup func(*resty.Request), result any) (*resty.Response, error) { |
| 164 | client := resty.New() |