我几天前就开始了我的新手.我想连接到mongodb,搜索,创建服务并将其用于角度.我几乎完成了所有事情,但我遇到了json.marshal()的问题.有人能告诉我我做错了什么,还是有更好的方法?谢谢 :)
错误是"./main.go:96:单值上下文中的多值json.Marshal()"
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/gorilla/mux"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"net/http"
)
type warrior struct {
Name string `json:"name"`
LowDamage int `json:"low_damage"`
HighDamage int `json:"high_damage"`
Health int `json:"health"`
HealthLeft int `json:"health_left"`
Armor int `json:"armor"`
Id bson.ObjectId "_id,omitempty"
}
func getWarriors(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
w.Write(mongo())
}
func main() {
// command line flags
port := flag.Int("port", 5001, "port to serve on")
dir := flag.String("random message 1", "web/", "random message 2")
flag.Parse()
// handle …Run Code Online (Sandbox Code Playgroud)