Esempio n. 1
0
func main() {

	var conf AppConfig
	err := common.ReadJson("./config.json", &conf)

	if err != nil {
		log.Fatal(">>>> Main app failed to start : ", err)
		return
	}

	if conf.Port == "" {
		conf.Port = "3001"
	}

	http.Handle("/", http.FileServer(http.Dir(conf.PublicFolderPath)))
	http.HandleFunc("/GetData", common.MakeHandler(GetData, conf.QueryEngineUrl))
	log.Println("Server started: http://localhost:" + conf.Port)
	log.Fatal(http.ListenAndServe(":"+conf.Port, nil))
}
Esempio n. 2
0
func GetData(w http.ResponseWriter, r *http.Request, data_file_path string) {
	r.ParseForm()

	logRequestData(r)

	var v structs.Data

	err := common.ReadJson(data_file_path, &v)

	if err != nil {
		log.Println(">>> Something went wrong : ", err)
	}

	for _, item := range v.Items {
		log.Println(item)

	}

	direction, ok := r.Form["direction"]
	column_name, _ := r.Form["col_name"]
	if ok {
		log.Println(">>> Sort direction", direction[0])
		log.Println(">>> Sort column", column_name[0])
		log.Println("UnMarshalled json data: ", v)
	} else {
		log.Println(r.Form)
	}

	v.Paginate.Direction = direction[0]
	v.Paginate.ColName = column_name[0]

	structs.OrderBy(v.Paginate.ColName, v.Paginate.Direction == "asc").Sort(v.Items)

	newBody, err := json.Marshal(v)
	if err != nil {
		log.Println("Error while marshalling ", err)
	}

	w.Write(newBody)
}