大家好,又见面了,我是你们的朋友全栈君。
直接贴代码
package main
import (
"io"
"net/http"
"encoding/json"
)
type KPI struct{
Fzi int `json:"fenzi"` //分子
Fmu int `json:"fenmu"` //分母
}
func kpi(w http.ResponseWriter, r *http.Request){
kk := KPI{199, 200}
res,_ := json.Marshal(kk)
w.Header().Set("content-type","application/json")
io.WriteString(w, string(res))
}
func main() {
http.HandleFunc("/", kpi)
http.ListenAndServe(":9999", nil)
}
验证结果