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

2
go.mod
View file

@ -1,3 +1,5 @@
module github.com/mdiluz/rove
go 1.14
require github.com/gorilla/mux v1.7.4

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=

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")
}