beerpong-elo/internal/beerpong-elo.go

46 lines
725 B
Go
Raw Normal View History

2025-01-05 02:53:54 +01:00
package beerpongelo
import (
"encoding/json"
"net/http"
"os"
"git.kapelle.org/niklas/beerpong-elo/internal/model"
"git.kapelle.org/niklas/beerpong-elo/internal/repo"
"git.kapelle.org/niklas/beerpong-elo/internal/web"
)
type Config struct {
}
func Start(config Config) {
repo := repo.NewInMemoryRepo()
loadFromFile(repo, "./data.json")
mux := web.CreateWebserver(repo)
http.ListenAndServe(":8080", mux)
}
func loadFromFile(repo repo.Repo, path string) error {
content, err := os.ReadFile(path)
if err != nil {
return err
}
var payload []model.InputGame
err = json.Unmarshal(content, &payload)
if err != nil {
return err
}
for _, game := range payload {
repo.AddGame(game)
}
return nil
}