Blog/api/Mindustry.go

34 lines
815 B
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package api
import (
"blog/utils"
"encoding/json"
"net/http"
)
func GetInfo(w http.ResponseWriter, r *http.Request) {
var (
err error
info utils.ServerInfo
)
if err = r.ParseForm(); err != nil {
http.Error(w, "参数解析错误", http.StatusInternalServerError)
}
host := r.Form.Get("host")
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)
}
if err != nil {
http.Error(w, "无法解析服务器数据", http.StatusInternalServerError)
}
}