UP Api
This commit is contained in:
@@ -3,5 +3,6 @@ package api
|
||||
import "net/http"
|
||||
|
||||
func InitApi() {
|
||||
http.HandleFunc("/api/bilibili", GetVideoData)
|
||||
BilibiliInit()
|
||||
http.HandleFunc("/api/mdt", GetInfo)
|
||||
}
|
||||
|
24
api/Mindustry.go
Normal file
24
api/Mindustry.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"blog/utils"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetInfo(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "参数解析错误", http.StatusInternalServerError)
|
||||
}
|
||||
host := r.Form.Get("host")
|
||||
info, err := utils.GetServerInfo(host)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
// 如果需要返回JSON数据给客户端,可以使用以下代码
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(info)
|
||||
if err != nil {
|
||||
http.Error(w, "无法解析服务器数据", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
@@ -224,3 +224,8 @@ func GetVideoData(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "无法解析视频数据", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func BilibiliInit() {
|
||||
http.HandleFunc("/api/bilibili", GetVideoData)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user