basic setup for HTTP handling

This commit is contained in:
Wouter Groeneveld 2021-04-07 10:06:16 +02:00
parent 3138a7f3ef
commit 42dd3fbe83
6 changed files with 58 additions and 2 deletions

16
app/index/handler.go Normal file
View File

@ -0,0 +1,16 @@
package index
import (
"net/http"
"fmt"
)
func HandleIndex(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Printf("testje")
}
//func (s *server) handleIndex() http.HandlerFunc {
//}

10
app/routes.go Normal file
View File

@ -0,0 +1,10 @@
package app
import (
"github.com/wgroeneveld/go-jamming/app/index"
)
func (s *server) routes() {
s.router.HandleFunc("/", index.HandleIndex)
}

24
app/server.go Normal file
View File

@ -0,0 +1,24 @@
package app
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
type server struct {
router *mux.Router
}
func Start() {
r := mux.NewRouter()
server := &server{router: r}
server.routes()
http.Handle("/", r)
fmt.Printf("Serving at port 1337...\n")
http.ListenAndServe(":1337", nil)
}

2
go.mod
View File

@ -1,3 +1,5 @@
module github.com/wgroeneveld/go-jamming
go 1.16
require github.com/gorilla/mux v1.8.0 // indirect

2
go.sum Normal file
View File

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

View File

@ -1,8 +1,10 @@
package main
import "fmt"
import (
"github.com/wgroeneveld/go-jamming/app"
)
func main() {
fmt.Println("it works!")
app.Start()
}