|
|
|
@ -3,6 +3,7 @@ package core |
|
|
|
import ( |
|
|
|
"aufs/db" |
|
|
|
"encoding/json" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
@ -73,24 +74,41 @@ func Scedit(w http.ResponseWriter, r *http.Request) { |
|
|
|
// 解析表单数据
|
|
|
|
r.ParseForm() |
|
|
|
// 接受json 数据
|
|
|
|
rcon, err := io.ReadAll(r.Body) |
|
|
|
if err != nil { |
|
|
|
// 解析失败返回错误信息
|
|
|
|
errorResp := map[string]string{"error": "body read error", "details": err.Error()} |
|
|
|
json.NewEncoder(w).Encode(errorResp) |
|
|
|
return |
|
|
|
} |
|
|
|
// 将传递过来的r.body 内容转为db.StServerInfo
|
|
|
|
var scinfo db.StServerInfo |
|
|
|
err := json.NewDecoder(r.Body).Decode(&scinfo) |
|
|
|
err = json.Unmarshal(rcon, &scinfo) |
|
|
|
if err != nil { |
|
|
|
// 解析失败返回错误信息
|
|
|
|
errorResp := map[string]string{"error": "JSON格式错误", "details": err.Error()} |
|
|
|
json.NewEncoder(w).Encode(errorResp) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 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.Init()
|
|
|
|
// 编辑
|
|
|
|
ret := db.UpdateServerInfo(scinfo) |
|
|
|
// ret := db.UpdateServerInfo(scinfo)
|
|
|
|
json.NewEncoder(w).Encode(map[string]string{ |
|
|
|
"message": "success", |
|
|
|
"status": "200", |
|
|
|
"data": strconv.Itoa(ret), |
|
|
|
"data": string(rcon), |
|
|
|
}) |
|
|
|
// 输出
|
|
|
|
// scresp := ScJson{
|
|
|
|
|