beerpong-elo/internal/beerpong-elo.go

54 lines
856 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) {
2025-01-11 00:03:26 +01:00
repo,err := repo.NewSQLRepo()
2025-01-05 02:53:54 +01:00
2025-01-11 00:03:26 +01:00
if err != nil {
panic(err)
}
//
// controller := newController(repo)
// loadFromFile(controller, "./data.json")
2025-01-05 02:53:54 +01:00
mux := web.CreateWebserver(repo)
http.ListenAndServe(":8080", mux)
}
2025-01-08 02:00:21 +01:00
func loadFromFile(c Controller, path string) error {
2025-01-05 02:53:54 +01:00
content, err := os.ReadFile(path)
if err != nil {
return err
}
2025-01-06 01:14:32 +01:00
var payload []model.Game
2025-01-05 02:53:54 +01:00
err = json.Unmarshal(content, &payload)
if err != nil {
return err
}
for _, game := range payload {
2025-01-11 00:03:26 +01:00
_, err = c.AddGame(game)
if err != nil{
panic(err)
}
2025-01-05 02:53:54 +01:00
}
return nil
}