示例#1
0
// Processes request for certain DB info, specified by dbName parameter
func GetDbInfo(w http.ResponseWriter, r *http.Request) {
	log.Info("GetDbInfo")

	dbName := mux.Vars(r)["dbName"]
	session := db.Session.Clone()
	defer session.Close()

	dbStats, err := db.GetDbStats(dbName)
	if err != nil {
		log.Error(err)
		w.WriteHeader(http.StatusInternalServerError)
	} else {
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		w.WriteHeader(http.StatusOK)
		if err := json.NewEncoder(w).Encode(dbStats); err != nil {
			log.Error(err)
		}
	}
}
示例#2
0
func main() {
	log.Info("Application starting")

	utils.SetDefaultConfig()

	db.InitDb()

	PrintClusterInfo()

	result, err := db.GetDbStats("test")
	if err != nil {
		log.Error(err)
		return
	}
	log.Info(result)

	router := api.NewRouter()
	http.ListenAndServe(":8080", router)

	log.Info("Application ready to receive requests")
}