-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (37 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
cos "github.com/samalgundi/api/lib/cos"
defs "github.com/samalgundi/api/lib/definitions"
)
func addCampSite(w http.ResponseWriter, r *http.Request) {
log.Println("Starting addCampSite execution:", r.FormValue("name"))
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form.
if err := r.ParseForm(); err != nil {
log.Println("ParseForm() err: ", err)
return
}
newCampsite := defs.NewLocation("campsite")
newCampsite.Name = r.FormValue("name")
newCampsite.Country = r.FormValue("country")
newCampsite.City = r.FormValue("city")
newCampsite.Zip = r.FormValue("zip")
// log.Println(newCampsite)
err := cos.PutObjectIntoCos(newCampsite)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
} else {
w.WriteHeader(http.StatusOK)
}
}
func main() {
log.Println("Starting api execution.")
//register URL paths and handlers
r := mux.NewRouter()
r.HandleFunc("/campsite", addCampSite).Methods("POST")
http.Handle("/", r)
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":8000", r))
}