28 lines
569 B
Go
28 lines
569 B
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.kapelle.org/niklas/beerpong-elo/internal/repo"
|
|
)
|
|
|
|
func CreateWebserver(repo repo.Repo) *http.ServeMux {
|
|
router := http.NewServeMux()
|
|
|
|
router.HandleFunc("GET /hello", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path)
|
|
})
|
|
|
|
router.HandleFunc("GET /games", func(w http.ResponseWriter, r *http.Request) {
|
|
games := repo.GetAllGames()
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(games)
|
|
})
|
|
|
|
return router
|
|
}
|