I’m trying to feed the results from the SQL Query into the Sum field of my 
struct however i’m met with this error despite their being a Sum Field in 
the struct.

The results from the query can range from 1-8 numbers depending on the date 
input in my REACT interface.

package main

import (
“encoding/json”
“log”
“net/http”
“time”
_ "github.com/go-sql-driver/mysql" 
"github.com/jmoiron/sqlx" 

)

type Tag struct {
Sum string json:"Sum"
Stream_count string json:"stream_count"
Query_desc string json:"Query_Desc"
Query_start_date string json:"Query_start_date"
Query_end_date string json:"Query_end_date"
Current_date string json:"Current_date"
Error_info string json:"Error_Info"
}

func handler(w http.ResponseWriter, r 
*http.Request) { w.Header().Set(“Access-Control-Allow-Origin”, "*")
w.Header().Set(“Access-Control-Allow-Headers”, “Origin, X-Requested-With, 
Content-Type, Accept”)
db, err := sqlx.Connect("mysql", "****")

date_1 := r.FormValue("date_1") 
date_2 := r.FormValue("date_2") 
time_1 := r.FormValue("time_1") 
time_2 := r.FormValue("time_2") 

var tag Tag 

Query := ("SELECT SUM(duration) Sum FROM sessions WHERE (app_id = '****' OR 
app_id ='****' OR app_id ='****' OR app_id ='****'OR app_id ='****') AND 
date(created ) between ? and ? and time(created ) between ? and ? AND 
(`media_src`='https://livestream.indemandradio.com/stream/index.m3u8' OR 
`media_src`='****' OR `media_src`='****' OR `media_src`='****' OR 
`media_src`='****' OR `media_src`='****') GROUP BY date(created)") err = 
db.Get(&tag, Query, date_1, date_2, time_1, time_2) log.Print(tag.Sum) 
tag.Query_desc = "Listener Hours" tag.Query_start_date = date_1 
tag.Query_end_date = date_2 dt := time.Now() tag.Current_date = 
dt.Format("01-02-2006 15:04:05") if err != nil {    tag.Error_info = 
err.Error() } j, err := json.Marshal(tag) if err != nil {   
 w.WriteHeader(http.StatusBadRequest)    w.Write([]byte((err.Error())))   
 return } w.Write(j) 

}

func main() {
http.HandleFunc(“/”, handler)
log.Fatal(http.ListenAndServe(“:8081”, nil))
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/38f01c42-8afb-476c-bce8-66466edb806fn%40googlegroups.com.

Reply via email to