func main() { users, _ := models.GetUser() fmt.Println(users) // initialize router rtr := mux.NewRouter() http.Handle("/", rtr) // routes rtr.HandleFunc("/hello/{name}", ctls.IndexHandler) rtr.HandleFunc("/user", ctls.UserHandler) // some server feedback log.Println("Listening...") http.ListenAndServe(":8000", nil) }
func UserHandler(w http.ResponseWriter, r *http.Request) { users, _ := models.GetUser() usersJson, _ := json.Marshal(users) w.Write(usersJson) }