Skip to content
Snippets Groups Projects
Commit 62d2bc60 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

testing gorilla/mux functionality

parent e2a36b71
No related branches found
No related tags found
No related merge requests found
...@@ -4,4 +4,4 @@ go 1.13 ...@@ -4,4 +4,4 @@ go 1.13
// +heroku goVersion go1.13 // +heroku goVersion go1.13
require github.com/gorilla/mux v1.7.3 // indirect require github.com/gorilla/mux v1.7.3
main 0 → 100755
File added
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"log"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
...@@ -10,21 +11,31 @@ import ( ...@@ -10,21 +11,31 @@ import (
func main() { func main() {
r := mux.NewRouter() r := mux.NewRouter()
r.HandleFunc("/", handlerHome)
r.HandleFunc("/hello/{name}/{gahe}", handlerHome2) c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()
c.HandleFunc("/country/{:country_identifier}", cHandler)
c.HandleFunc("/species/{:speciesKey}", sHandler)
c.HandleFunc("/diag/", dHandler)
http.Handle("/", r) http.Handle("/", r)
http.ListenAndServe(":5000", nil) log.Fatal(http.ListenAndServe(":5000", nil))
}
func dHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "aiaiai")
} }
func handlerHome(w http.ResponseWriter, r *http.Request) { func cHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "aiaiai") fmt.Fprintln(w, "aiaiai")
} }
func handlerHome2(w http.ResponseWriter, r *http.Request) { func sHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) fmt.Fprintln(w, "aiaiai")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Name: %v%v\n", vars["name"], vars["gahe"])
} }
\ No newline at end of file
package models
package models
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment