(url string, request modelApplyRequest)
| 93 | } |
| 94 | |
| 95 | func postModelApplyRequest(url string, request modelApplyRequest) (response map[string]any) { |
| 96 | |
| 97 | //url := "http://localhost:AI/models/apply" |
| 98 | |
| 99 | // Create the request payload |
| 100 | |
| 101 | payload, err := json.Marshal(request) |
| 102 | if err != nil { |
| 103 | fmt.Println("Error marshaling JSON:", err) |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | // Create the HTTP request |
| 108 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload)) |
| 109 | if err != nil { |
| 110 | fmt.Println("Error creating request:", err) |
| 111 | return |
| 112 | } |
| 113 | req.Header.Set("Content-Type", "application/json") |
| 114 | req.Header.Set("Authorization", bearerKey) |
| 115 | |
| 116 | // Make the request |
| 117 | client := &http.Client{} |
| 118 | resp, err := client.Do(req) |
| 119 | if err != nil { |
| 120 | fmt.Println("Error making request:", err) |
| 121 | return |
| 122 | } |
| 123 | defer resp.Body.Close() |
| 124 | |
| 125 | body, err := io.ReadAll(resp.Body) |
| 126 | if err != nil { |
| 127 | fmt.Println("Error reading response body:", err) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | // Unmarshal the response into a map[string]interface{} |
| 132 | err = json.Unmarshal(body, &response) |
| 133 | if err != nil { |
| 134 | fmt.Println("Error unmarshaling JSON response:", err) |
| 135 | return |
| 136 | } |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | func postRequestJSON[B any](url string, bodyJson *B) error { |
| 141 | payload, err := json.Marshal(bodyJson) |
no test coverage detected