@dhruvdutt/

Appbase.io - Go - range

Go

Range query to get all rooms between prices `50` and `100`

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.25733373365571066","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAogICJzdHJpbmdzIgogICJuZXQvaHR0cCIKICAiaW8vaW91dGlsIgogICJlbmNvZGluZy9qc29uIgogICJieXRlcyIKICAiZm10IgopCgpmdW5jIG1haW4oKSB7CgogIHVybCA6PSAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9ob3VzaW5nLWRlbW8vbGlzdGluZy9fc2VhcmNoIgoKICBwYXlsb2FkIDo9IHN0cmluZ3MuTmV3UmVhZGVyKGB7CiAgICAicXVlcnkiOiB7CiAgICAgICJyYW5nZSI6IHsKICAgICAgICAicHJpY2UiOiB7CiAgICAgICAgICAiZ3RlIjogNTAsCiAgICAgICAgICAibHRlIjogMTAwCiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfWApCgogIHJlcSwgXyA6PSBodHRwLk5ld1JlcXVlc3QoIlBPU1QiLCB1cmwsIHBheWxvYWQpCgogIHJlcS5IZWFkZXIuQWRkKCJBdXRob3JpemF0aW9uIiwgIkJhc2ljIFdXNURaMVozYjNwV09tVTVaV00xWTJJd0xUVTRaRGd0TkdKaU1DMWlZV1JqTFdGallXWTNNalkyTmpGbU1RPT0iKQogIHJlcS5IZWFkZXIuQWRkKCJDb250ZW50LVR5cGUiLCAiYXBwbGljYXRpb24vanNvbiIpCgogIHJlcywgXyA6PSBodHRwLkRlZmF1bHRDbGllbnQuRG8ocmVxKQoKICBkZWZlciByZXMuQm9keS5DbG9zZSgpCiAgYm9keSwgXyA6PSBpb3V0aWwuUmVhZEFsbChyZXMuQm9keSkKCiAgLy8gcHJldHRpZnkKICB2YXIgcHJldHR5SlNPTiBieXRlcy5CdWZmZXIKICBlcnJvciA6PSBqc29uLkluZGVudCgmcHJldHR5SlNPTiwgYm9keSwgIiIsICJcdCIpCiAgaWYgZXJyb3IgIT0gbmlsIHsKICAgIGZtdC5QcmludGxuKCJKU09OIHBhcnNlIGVycm9yOiAiLCBlcnJvcikKICAgIHJldHVybgogIH0KCiAgZm10LlByaW50bG4oc3RyaW5nKHByZXR0eUpTT04uQnl0ZXMoKSkpCgp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
  "strings"
  "net/http"
  "io/ioutil"
  "encoding/json"
  "bytes"
  "fmt"
)

func main() {

  url := "https://scalr.api.appbase.io/housing-demo/listing/_search"

  payload := strings.NewReader(`{
    "query": {
      "range": {
        "price": {
          "gte": 50,
          "lte": 100
        }
      }
    }
  }`)

  req, _ := http.NewRequest("POST", url, payload)

  req.Header.Add("Authorization", "Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==")
  req.Header.Add("Content-Type", "application/json")

  res, _ := http.DefaultClient.Do(req)

  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  // prettify
  var prettyJSON bytes.Buffer
  error := json.Indent(&prettyJSON, body, "", "\t")
  if error != nil {
    fmt.Println("JSON parse error: ", error)
    return
  }

  fmt.Println(string(prettyJSON.Bytes()))

}