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