Skip to content
Snippets Groups Projects
Commit d31a584a authored by jotangen's avatar jotangen
Browse files

added default handler /

parent ec62bb0a
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"html"
"log" "log"
"net/http" "net/http"
"os" "os"
...@@ -33,6 +34,7 @@ func urlSplitForCountry(a string)(string, string){ ...@@ -33,6 +34,7 @@ func urlSplitForCountry(a string)(string, string){
func defaultHandler(w http.ResponseWriter, r *http.Request){ func defaultHandler(w http.ResponseWriter, r *http.Request){
//code to be added //code to be added
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
} }
func viewHandler(w http.ResponseWriter, r *http.Request) { func viewHandler(w http.ResponseWriter, r *http.Request) {
...@@ -82,7 +84,7 @@ var Start time.Time ...@@ -82,7 +84,7 @@ var Start time.Time
// Main function // Main function
func main() { func main() {
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port == "" { if port == "" {
//log.fatal formatting output and exits //log.fatal formatting output and exits
log.Fatal("$PORT must be set") log.Fatal("$PORT must be set")
...@@ -94,7 +96,7 @@ func main() { ...@@ -94,7 +96,7 @@ func main() {
// under the path / remember to end with trailing / // under the path / remember to end with trailing /
// Add code to this function // Add code to this function
http.HandleFunc("/conservation/v1/", defaultHandler) http.HandleFunc("/", defaultHandler)
http.HandleFunc("/conservation/v1/country/name/", viewHandler) http.HandleFunc("/conservation/v1/country/name/", viewHandler)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment