Add a basic server router to main

This commit is contained in:
Marc Di Luzio 2020-05-29 17:41:11 +01:00
parent 9deda4b3fb
commit 5377e42e71
3 changed files with 22 additions and 2 deletions

20
main.go
View file

@ -1,7 +1,23 @@
package main
import "fmt"
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
fmt.Printf("Hello World")
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", HandleRoot)
if err := http.ListenAndServe(":8080", router); err != nil {
log.Fatal(err)
}
}
func HandleRoot(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}