routes.go 403 B

12345678910111213141516171819202122232425
  1. package server
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. func initRoutes() {
  7. http.HandleFunc("/", index)
  8. http.HandleFunc("/countries", func(w http.ResponseWriter, r *http.Request) {
  9. switch r.Method {
  10. case http.MethodGet:
  11. getCountries(w, r)
  12. case http.MethodPost:
  13. addCountry(w, r)
  14. default:
  15. w.WriteHeader(http.StatusMethodNotAllowed)
  16. fmt.Fprintf(w, "Method not allowed")
  17. return
  18. }
  19. })
  20. }