Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func main() {
- db = models.DB{}
- db.Open()
- r := mux.NewRouter()
- r.HandleFunc("/index", IndexHandler).Methods("GET")
- r.HandleFunc("/add", AddHandler).Methods("POST")
- r.HandleFunc("/knife/{id}", KnifeHandler).Methods("GET")
- r.PathPrefix("/").Handler(http.FileServer(http.Dir("./")))
- http.Handle("/", r)
- http.ListenAndServe(":1111", nil)
- db.Close()
- }
- func KnifeHandler(w http.ResponseWriter, r *http.Request) {
- vars := mux.Vars(r)
- tmpl, _ := template.ParseFiles("eachKnife.html")
- tmpl.ExecuteTemplate(w, "knife", nil)
- ID := vars["id"]
- knife := db.GetKnife(ID)
- knifeJSON, _ := json.Marshal(knife)
- w.Write(knifeJSON)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement