这是我在 Go 中的代码,我猜一切都是正确的......
package main
import(
"fmt"
"encoding/json"
"net/http"
)
type Payload struct {
Stuff Data
}
type Data struct {
Fruit Fruits
Veggies Vegetables
}
type Fruits map[string]int
type Vegetables map[string]int
func serveRest(w http.ResponseWriter, r *httpRequest){
response , err := getJsonResponse()
if err != nil{
panic(err)
}
fmt.println(w, string(response))
}
func main(){
http.HandleFucn("/", serveRest)
http.ListenAndServe("localhost:1337",nil)
}
func getJsonResponse() ([]byte, error){
fruits := make(map[string]int)
fruits["Apples"] = 25
fruits["Oranges"] = 11
vegetables := make(map[string]int)
vegetables["Carrots"] = 21
vegetables["Peppers"] = 0
d := Data{fruits, vegetables}
p := Payload{d}
return json.MarshalIndent(p, "", " ")
}
这是我得到的错误
API_Sushant.go:31: syntax error: unexpected string literal, expecting semicolon or newline or }
谁能告诉我错误是什么请....
繁花不似锦
相关分类