28 lines
569 B
Go
Raw Normal View History

2025-01-05 02:53:54 +01:00
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
}