CMogilko on v6.2.2
CMogilko on master
upgrade version golang.org/x/sy… (compare)
net/http
isn't a good practice
func fastHandler(w http.ResponseWriter, req *http.Request) {
res, err := r.DB("pi_baker").Table("observations").
OrderBy(r.Desc("datetime")).
Limit(5760).
Pluck("datetime", "temp", "humidity").
Run(session)
if err != nil {
log.Fatalln(err.Error())
}
w.Header().Set("Content-Type", "application/json")
encoder := json.NewEncoder(w)
var row map[string]interface{}
for res.Next(&row) {
err = encoder.Encode(row)
if err != nil {
// Oh no! Something bad happened!
// Since we're not buffering the response, we aren't going to send an
// error code and message. Maybe you can log the error and continue.
}
}
}
[
,commas between each item, and ]
) or make your handler consume it line-by-line.
.Encode()
will write each object to the http connection, not storing it in memory. Probably the best way to handle actually massive amounts of data.
var results []map[string]interface{} = make([]map[string]interface{}, 0)
var row map[string]interface{}
for res.Next(&row) {
results = append(results, row)
}
jsonBytes, err := json.Marshal(results)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
// Logging goes here
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(jsonBytes)
How would I accomplish this in GoRethink?
r.db("store").table("shelves").filter(r.row("products").contains(function(product) { return product('id').eq("122f0054-fb41-46d6-9c50-bc158ec9a2ff") }))
I've scoured the GitHub repo & docs but am none the wiser. I assume this is quite simple & I'm just missing something?
Run
and One
?
CreatedAt
field to time.Time and setting it with time.Now()
instead of db.Now()
Term
) I think using the Go time package is the best thing for you to do