init commit

This commit is contained in:
2025-04-09 15:52:24 +08:00
parent d1c5fb1162
commit a5b87653a3
31 changed files with 718 additions and 24 deletions
+41
View File
@@ -0,0 +1,41 @@
package images
import (
"context"
"encoding/json"
"floares/config"
"fmt"
"log"
"net/http"
)
type DeleteRsp struct {
Cause string `json:"cause"` //cause image is in use by a container
Message string `json:"message"`
Response int `json:"response"`
}
type DeleteRsult struct {
Code int `json:"code"`
Error string `json:"err,omitempty"`
}
func Delete(id string) DeleteRsult {
req, _ := http.NewRequestWithContext(context.Background(), http.MethodDelete, config.Entrypoint+fmt.Sprintf("/images/%s", id), nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return DeleteRsult{
Error: err.Error(),
}
}
var deleteRsult DeleteRsp
var response DeleteRsult
response.Code = resp.StatusCode
_ = json.NewDecoder(resp.Body).Decode(&deleteRsult)
log.Println(deleteRsult)
if deleteRsult.Cause != "" {
return DeleteRsult{
Error: deleteRsult.Cause,
}
}
return response
}