diff --git a/backend/connector_couchdb.go b/backend/connector_couchdb.go index d93ab2f..f08adce 100644 --- a/backend/connector_couchdb.go +++ b/backend/connector_couchdb.go @@ -1,7 +1,10 @@ package main import ( + "encoding/json" "fmt" + "log" + "net/http" "net/url" "reflect" "time" @@ -70,3 +73,56 @@ func addNewCard(_isQuestion bool, _blank int, _text string) error { fmt.Printf(result.ID) return nil } + +var myClient = &http.Client{Timeout: 10 * time.Second} + +func getJson(url string, target interface{}) error { + r, err := myClient.Get(url) + if err != nil { + return err + } + defer r.Body.Close() + + return json.NewDecoder(r.Body).Decode(target) +} + +func getAllDoc() { + // db := connectCouchdb() + // zmiena := db.AllDocs() + // allCards := []Card{} + + resp, err := http.Get("http://localhost:5984/golang_cards/_all_docs?include_docs=true") + if err != nil { + log.Fatal(err) + } + var generic map[string]interface{} + //fmt.Println(resp.Body) //&{0xc000040740 {0 0} false 0x693ad0 0x693a50} + + err = json.NewDecoder(resp.Body).Decode(&generic) + if err != nil { + log.Fatal(err) + } + keys := reflect.ValueOf(generic).MapKeys() + fmt.Println("KEYS: ", keys) + + // 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) + + // } + // // default: + // // fmt.Println(k, "is unknown type") + // } + // } + // } + // fmt.Println("Zmienna: ", zmiena) + +} diff --git a/backend/main.go b/backend/main.go index 6a2acdc..0bd6f96 100644 --- a/backend/main.go +++ b/backend/main.go @@ -61,6 +61,7 @@ func main() { api.POST("/getAllLoggedUsersView", getAllLoggedUsersView) // [mysql] pobieranie listy zalogowanych uzytkownikow api.POST("/updateLoggedUserView", updateLoggedUserView) //aktualizacja ze uzytkownik zalogowany api.POST("/updateLogoutUserView", updateLogoutUserView) //aktualizacja stanu jak uzytkownik sie wyloguje + api.POST("/getAllDocView", getAllDocView) //pobieranie wszystkich kart z couchd // Start and run the server router.Run(":3000") diff --git a/backend/views.go b/backend/views.go index c0b93d7..6f4a5c3 100644 --- a/backend/views.go +++ b/backend/views.go @@ -255,3 +255,8 @@ func updateLogoutUserView(c *gin.Context) { func getGentelman(c *gin.Context) { //zwraca login aktualnego gentelamana } + +func getAllDocView(c *gin.Context) { + fmt.Println("DLA couchdb") + getAllDoc() +}