|
|
@ -21,6 +21,10 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func setupRoutes(mux *http.ServeMux) {
|
|
|
|
func setupRoutes(mux *http.ServeMux) {
|
|
|
|
|
|
|
|
counter := 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// API Routes
|
|
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
mux.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Method != http.MethodGet {
|
|
|
|
if r.Method != http.MethodGet {
|
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
@ -36,6 +40,52 @@ func setupRoutes(mux *http.ServeMux) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("/api/value", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
if r.Method != http.MethodGet {
|
|
|
|
|
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
err := json.NewEncoder(w).Encode(counter)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("/api/increment", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
if r.Method != http.MethodPost {
|
|
|
|
|
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
err := json.NewEncoder(w).Encode(counter)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("/api/decrement", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
if r.Method != http.MethodPost {
|
|
|
|
|
|
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
err := json.NewEncoder(w).Encode(counter)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Static Files
|
|
|
|
// Static Files
|
|
|
|
mux.Handle("/", http.FileServer(http.Dir("./dist/")))
|
|
|
|
mux.Handle("/", http.FileServer(http.Dir("./dist/")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|