|
|
|
@ -3,7 +3,6 @@ package core |
|
|
|
import ( |
|
|
|
"aufs/db" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
@ -59,18 +58,44 @@ func Scedit(w http.ResponseWriter, r *http.Request) { |
|
|
|
if r.Method != http.MethodPost { |
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
|
|
|
return |
|
|
|
} else { |
|
|
|
// 设置响应头为JSON格式
|
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "*") // 允许跨域(生产环境需指定具体域名)
|
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS") |
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type") |
|
|
|
// 处理预检请求
|
|
|
|
if r.Method == http.MethodOptions { |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 解析表单数据
|
|
|
|
// r.ParseForm()
|
|
|
|
// 接受json 数据
|
|
|
|
var scinfo db.StServerInfo |
|
|
|
err := json.NewDecoder(r.Body).Decode(&scinfo) |
|
|
|
if err != nil { |
|
|
|
// 解析失败返回错误信息
|
|
|
|
errorResp := map[string]string{"error": "JSON格式错误", "details": err.Error()} |
|
|
|
json.NewEncoder(w).Encode(errorResp) |
|
|
|
return |
|
|
|
} |
|
|
|
defer r.Body.Close() |
|
|
|
// 处理接收的json
|
|
|
|
// 数据库初始化
|
|
|
|
db.Init() |
|
|
|
// 编辑
|
|
|
|
db.UpdateServerInfo(scinfo) |
|
|
|
// 输出
|
|
|
|
scresp := ScJson{ |
|
|
|
Message: "success", |
|
|
|
Status: 200, |
|
|
|
Data: []db.StServerInfo{scinfo}, |
|
|
|
} |
|
|
|
uCorsHadler(w, r) |
|
|
|
json.NewEncoder(w).Encode(scresp) |
|
|
|
|
|
|
|
} |
|
|
|
// 解析表单数据
|
|
|
|
frmdata := r.ParseForm() |
|
|
|
fmt.Println(frmdata) |
|
|
|
// 获取参数
|
|
|
|
// id := frmdata.Get("id")
|
|
|
|
// // 转换为整数
|
|
|
|
// scid, err := strconv.Atoi(id)
|
|
|
|
// if err != nil {
|
|
|
|
// // 处理转换错误
|
|
|
|
// }
|
|
|
|
// 数据库初始化
|
|
|
|
db.Init() |
|
|
|
// 编辑
|
|
|
|
|
|
|
|
} |
|
|
|
|