diff --git a/api.go b/api.go new file mode 100644 index 0000000..2e8cb1a --- /dev/null +++ b/api.go @@ -0,0 +1,63 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +type APIServer struct { + Host string + Port string +} + +type APIError struct { + Error string +} + +func WriteJSON(w http.ResponseWriter, status int, v any) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + return json.NewEncoder(w).Encode(v) +} + +func NewAPIServer(cfg Config) *APIServer { + return &APIServer{ + Host: cfg.Host, + } +} + +func (s *APIServer) Start() { + router := mux.NewRouter() + router.HandleFunc("/prerace", s.handleCreatePreRace).Methods("POST") + router.HandleFunc("/preraces", s.handleGetPreRaces).Methods("GET") + router.HandleFunc("prerace", s.handleDeletePreRace).Methods("DELETE") + router.HandleFunc("prerace", s.handleUpdatePreRace).Methods("PUT") + + log.Println("Listening for new Preraces / Races") + + http.ListenAndServe(s.Host, router) + +} + +func (s *APIServer) handleGetPreRaceByID(w http.ResponseWriter, r *http.Request) { + +} + +func (s *APIServer) handleGetPreRaces(w http.ResponseWriter, r *http.Request) { + +} + +func (s *APIServer) handleCreatePreRace(w http.ResponseWriter, r *http.Request) { + +} + +func (s *APIServer) handleDeletePreRace(w http.ResponseWriter, r *http.Request) { + +} + +func (s *APIServer) handleUpdatePreRace(w http.ResponseWriter, r *http.Request) { + +} diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..bd61fbd --- /dev/null +++ b/config.toml @@ -0,0 +1,6 @@ +# config.toml +host = "0.0.0.0:3000" +# TMDbApiKey is required +tmdbApiKey = "" +dbName = "racer" +uploadFolder = "/home/rouggy/torrents/rtorrent/Race" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ffaba1d --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module git.rouggy.com/GoRacerr + +go 1.22.4 + +require github.com/BurntSushi/toml v1.4.0 + +require github.com/gorilla/mux v1.8.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3160ef1 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/goracerr.log b/goracerr.log new file mode 100644 index 0000000..aa8a254 --- /dev/null +++ b/goracerr.log @@ -0,0 +1,13 @@ +2024/08/30 11:41:30 Starting GoRacerr on port 3000 +2024/08/30 11:42:48 Starting GoRacerr on port 3000 +[GoRacerr]2024/08/30 11:50:38 Starting GoRacerr on port 3000 +[GoRacerr]2024/08/30 12:10:37 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:11:13 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:11:41 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:12:05 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:12:23 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:12:23 Listening for new Preraces / Races +[GoRacerr]2024/08/30 12:12:45 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:12:45 Listening for new Preraces / Races +[GoRacerr]2024/08/30 12:22:46 Starting GoRacerr on 0.0.0.0:3000 +[GoRacerr]2024/08/30 12:22:46 Listening for new Preraces / Races diff --git a/race.go b/race.go new file mode 100644 index 0000000..491fa26 --- /dev/null +++ b/race.go @@ -0,0 +1,23 @@ +package main + +type Race struct { + TorrentName string `json:"torrentname"` + Category string `json:"category"` + Indexer string `json:"indexer"` + Type string `json:"type"` + Title string `json:"title"` + Season string `json:"season"` + Episode string `json:"episode"` + Year string `json:"year"` + Resolution string `json:"resolution"` + Source string `json:"source"` + TorrentURL string `json:"torrenturl"` + Won bool `json:"won"` + PreRace bool `json:"prerace"` +} + +func NewRace(torrentName string) *Race { + return &Race{ + TorrentName: torrentName, + } +}