This commit is contained in:
Gregory Salaun 2024-08-30 12:36:47 +07:00
parent 0fa3b1f43f
commit 8edcf4c678
6 changed files with 116 additions and 0 deletions

63
api.go Normal file
View File

@ -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) {
}

6
config.toml Normal file
View File

@ -0,0 +1,6 @@
# config.toml
host = "0.0.0.0:3000"
# TMDbApiKey is required
tmdbApiKey = ""
dbName = "racer"
uploadFolder = "/home/rouggy/torrents/rtorrent/Race"

7
go.mod Normal file
View File

@ -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

4
go.sum Normal file
View File

@ -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=

13
goracerr.log Normal file
View File

@ -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

23
race.go Normal file
View File

@ -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,
}
}