beerpong-elo/internal/beerpong-elo.go

54 lines
856 B
Go

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,err := repo.NewSQLRepo()
if err != nil {
panic(err)
}
//
// controller := newController(repo)
// loadFromFile(controller, "./data.json")
mux := web.CreateWebserver(repo)
http.ListenAndServe(":8080", mux)
}
func loadFromFile(c Controller, path string) error {
content, err := os.ReadFile(path)
if err != nil {
return err
}
var payload []model.Game
err = json.Unmarshal(content, &payload)
if err != nil {
return err
}
for _, game := range payload {
_, err = c.AddGame(game)
if err != nil{
panic(err)
}
}
return nil
}