UP MDTApi

main
JiXieShi 2024-05-27 19:00:33 +08:00
parent ed9a47c5ad
commit 4b29709791
2 changed files with 17 additions and 8 deletions

View File

@ -7,17 +7,26 @@ import (
) )
func GetInfo(w http.ResponseWriter, r *http.Request) { func GetInfo(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil { var (
err error
info utils.ServerInfo
)
if err = r.ParseForm(); err != nil {
http.Error(w, "参数解析错误", http.StatusInternalServerError) http.Error(w, "参数解析错误", http.StatusInternalServerError)
} }
host := r.Form.Get("host") host := r.Form.Get("host")
info, err := utils.GetServerInfo(host) if host != "" {
if err != nil { info, err = utils.GetServerInfo(host)
http.Error(w, err.Error(), http.StatusInternalServerError) //if err != nil {
} // http.Error(w, err.Error(), http.StatusInternalServerError)
//}
// 如果需要返回JSON数据给客户端可以使用以下代码 // 如果需要返回JSON数据给客户端可以使用以下代码
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json;charset=utf-8")
err = json.NewEncoder(w).Encode(info) err = json.NewEncoder(w).Encode(info)
} else {
http.Error(w, "参数为空", http.StatusInternalServerError)
}
if err != nil { if err != nil {
http.Error(w, "无法解析服务器数据", http.StatusInternalServerError) http.Error(w, "无法解析服务器数据", http.StatusInternalServerError)
} }

View File

@ -218,7 +218,7 @@ func GetVideoData(w http.ResponseWriter, r *http.Request) {
} }
// 如果需要返回JSON数据给客户端可以使用以下代码 // 如果需要返回JSON数据给客户端可以使用以下代码
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json;charset=utf-8")
err = json.NewEncoder(w).Encode(info) err = json.NewEncoder(w).Encode(info)
if err != nil { if err != nil {
http.Error(w, "无法解析视频数据", http.StatusInternalServerError) http.Error(w, "无法解析视频数据", http.StatusInternalServerError)