[couchdb] Pobranie wszystkich danych z dokuemntu

This commit is contained in:
pawlaczyk 2019-01-13 06:18:43 +01:00
parent aef835e620
commit 53ec7d5178
2 changed files with 17 additions and 18 deletions

View File

@ -105,36 +105,34 @@ func getAllDoc() {
keys := reflect.ValueOf(generic).MapKeys()
fmt.Println("KEYS: ", keys)
// allCards := []Card{}
for k, v := range generic {
if k == "rows" {
switch val := v.(type) {
// case string:
// fmt.Println(k, "is string", val)
// case int:
// fmt.Println(k, "is int", val)
case []interface{}:
fmt.Println(k, "is an array")
for _, v := range val {
// fmt.Println(v) //, i)
// fmt.Println(reflect.TypeOf(v))
// fmt.Println(i)
var tmpCard Card
mResult := v.(map[string]interface{})
// fmt.Println(mResult["doc"])
// fmt.Println(reflect.TypeOf(mResult["doc"]))
mResult2 := mResult["doc"].(map[string]interface{})
// fmt.Println(reflect.TypeOf(mResult2))
fmt.Println(mResult2["Text"])
fmt.Println(reflect.TypeOf(mResult2["Text"]))
tmpCard.Text = mResult2["Text"].(string)
fmt.Println(mResult2["Timestamp"])
fmt.Println(mResult2["_id"])
fmt.Println(mResult2["blank"])
tmpCard.Timestamp = mResult2["Timestamp"].(float64)
// mResult2 := mResult.(map[string]interface{})
// fmt.Println(mResult2["Timestamp"])
fmt.Println(mResult2["_id"])
tmpCard.Id = mResult2["_id"].(string)
fmt.Println(mResult2["blank"])
tmpCard.Blank = int(mResult2["blank"].(float64))
fmt.Println(mResult2["isquestion"])
tmpCard.IsQuestion = mResult2["isquestion"].(bool)
}
// default:
// fmt.Println(k, "is unknown type")
}
}
}

View File

@ -29,8 +29,9 @@ type User struct {
*/
type Card struct {
couchdb.Document
Id int `json:"id" binding:"required"`
Id string `json:"id" binding:"required"`
IsQuestion bool `json:"isQuestion"` //0 karta pytanie, 1 karta odpowiedź
Blank int `json:"blank" binding:"required"` //ile kart odpowiedzi na pytanie
Text string `json:"text" binding:"required"` // podłoga to luka
Timestamp float64
}