Commit e2a36b71 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

works

parent c17f5352
......@@ -2,4 +2,6 @@ module assignment-1
go 1.13
// +heroku goVersion go1.13
\ No newline at end of file
// +heroku goVersion go1.13
require github.com/gorilla/mux v1.7.3 // indirect
......@@ -3,17 +3,28 @@ package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func main() {
http.HandleFunc("/hello", handlerHello)
http.ListenAndServe("localhost:8080", nil)
r := mux.NewRouter()
r.HandleFunc("/", handlerHome)
r.HandleFunc("/hello/{name}/{gahe}", handlerHome2)
}
func handlerHello(w http.ResponseWriter, r *http.Request) {
http.Handle("/", r)
http.ListenAndServe(":5000", nil)
}
fmt.Fprintln(w, "hello")
func handlerHome(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "aiaiai")
}
}
\ No newline at end of file
func handlerHome2(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Name: %v%v\n", vars["name"], vars["gahe"])
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment