(baseUrl, key string, body map[string]any)
| 131 | } |
| 132 | |
| 133 | func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http.Response, error) { |
| 134 | requestUrl := fmt.Sprintf("%s/suno/fetch", baseUrl) |
| 135 | byteBody, err := json.Marshal(body) |
| 136 | if err != nil { |
| 137 | return nil, err |
| 138 | } |
| 139 | |
| 140 | req, err := http.NewRequest("POST", requestUrl, bytes.NewBuffer(byteBody)) |
| 141 | if err != nil { |
| 142 | common.SysError(fmt.Sprintf("Get Task error: %v", err)) |
| 143 | return nil, err |
| 144 | } |
| 145 | defer req.Body.Close() |
| 146 | // 设置超时时间 |
| 147 | timeout := time.Second * 15 |
| 148 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 149 | defer cancel() |
| 150 | // 使用带有超时的 context 创建新的请求 |
| 151 | req = req.WithContext(ctx) |
| 152 | req.Header.Set("Content-Type", "application/json") |
| 153 | req.Header.Set("Authorization", "Bearer "+key) |
| 154 | resp, err := service.GetHttpClient().Do(req) |
| 155 | if err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | return resp, nil |
| 159 | } |
| 160 | |
| 161 | func actionValidate(c *gin.Context, sunoRequest *dto.SunoSubmitReq, action string) (err error) { |
| 162 | switch action { |
nothing calls this directly
no test coverage detected