initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"up/utils"
|
||||
)
|
||||
|
||||
func ExtlinuxRead(w http.ResponseWriter, req *http.Request) {
|
||||
if utils.MountDevice() < 0 {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
http.Error(w, "{\"error\":\"Failed to mount device\"}", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data, err := os.ReadFile(os.Getenv("MOUNT_POINT") + "/" + os.Getenv("EXTLINUX_FILE"))
|
||||
if err != nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
http.Error(w, "{\"error\":\"extlinux.conf not found\"}", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"content": string(data),
|
||||
"size": len(data),
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
// В случае ошибки кодирования уже ничего не сделать,
|
||||
// можно только залогировать (здесь опущено для краткости)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user