u
This commit is contained in:
parent
d976bb4a59
commit
caeeb437ee
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "RaceBot.go"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -44,5 +45,5 @@ func SQLiteMigrate() {
|
|||||||
if err := db.AutoMigrate(&models.Release{}, &models.Race{}).Error; err != nil {
|
if err := db.AutoMigrate(&models.Release{}, &models.Race{}).Error; err != nil {
|
||||||
panic("[Database] Failed migrating database: ")
|
panic("[Database] Failed migrating database: ")
|
||||||
}
|
}
|
||||||
fmt.Println("[Database] Database successfully migrated")
|
log.Println("[Database] Database successfully migrated")
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# config.toml
|
# config.toml
|
||||||
host = "127.0.0.1"
|
host = "0.0.0.0"
|
||||||
port = "3000"
|
port = "3000"
|
||||||
# TMDbApiKey is required
|
# TMDbApiKey is required
|
||||||
tmdbApiKey = ""
|
tmdbApiKey = ""
|
||||||
|
1
go.mod
1
go.mod
@ -5,7 +5,6 @@ go 1.20
|
|||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.9.0
|
github.com/gin-gonic/gin v1.9.0
|
||||||
github.com/jinzhu/gorm v1.9.16
|
github.com/jinzhu/gorm v1.9.16
|
||||||
github.com/joho/godotenv v1.5.1
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
github.com/moistari/rls v0.5.9
|
github.com/moistari/rls v0.5.9
|
||||||
github.com/spf13/viper v1.15.0
|
github.com/spf13/viper v1.15.0
|
||||||
|
2
go.sum
2
go.sum
@ -162,8 +162,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
|
|||||||
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package race
|
|
||||||
|
|
||||||
import "github.com/jinzhu/gorm"
|
|
||||||
|
|
||||||
type Race struct {
|
|
||||||
gorm.Model
|
|
||||||
Hash string `gorm:"column:hash;type:varchar(50)" form:"hash" json:"hash" binding:"max=50"`
|
|
||||||
TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"`
|
|
||||||
Category string `gorm:"column:category;varchar(50);not null" form:"category" json:"category" binding:"max=50"`
|
|
||||||
ContentPath string `gorm:"column:content_path;varchar(100);not null" form:"content_path" json:"content_path" binding:"max=100"`
|
|
||||||
RootPath string `gorm:"column:root_path;varchar(100)" form:"root_path" json:"root_path" binding:"max=100"`
|
|
||||||
Size string `gorm:"column:size;varchar(15)" form:"size" json:"size" binding:"max=15"`
|
|
||||||
Won bool `gorm:"column:won;bool" form:"won" json:"won"`
|
|
||||||
}
|
|
@ -10,10 +10,18 @@ type Race struct {
|
|||||||
Hash string `gorm:"column:hash;type:varchar(50)" form:"hash" json:"hash" binding:"max=50"`
|
Hash string `gorm:"column:hash;type:varchar(50)" form:"hash" json:"hash" binding:"max=50"`
|
||||||
TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"`
|
TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"`
|
||||||
Category string `gorm:"column:category;varchar(50);not null" form:"category" json:"category" binding:"max=50"`
|
Category string `gorm:"column:category;varchar(50);not null" form:"category" json:"category" binding:"max=50"`
|
||||||
ContentPath string `gorm:"column:content_path;varchar(100);not null" form:"content_path" json:"content_path" binding:"max=100"`
|
Indexer string `gorm:"column:indexer;varchar(20);not null" form:"indexer" json:"indexer" binding:"max=20"`
|
||||||
RootPath string `gorm:"column:root_path;varchar(100)" form:"root_path" json:"root_path" binding:"max=100"`
|
Type string `gorm:"column:type;varchar(20)" form:"type" json:"type" binding:"max=20"`
|
||||||
Size string `gorm:"column:size;varchar(15)" form:"size" json:"size" binding:"max=15"`
|
Title string `gorm:"column:title;varchar(20)" form:"title" json:"title" binding:"max=20"`
|
||||||
|
Season string `gorm:"column:season;varchar(2)" form:"season" json:"season" binding:"max=2"`
|
||||||
|
Episode string `gorm:"column:episode;varchar(4)" form:"episode" json:"episode" binding:"max=4"`
|
||||||
|
Year string `gorm:"column:year;varchar(4)" form:"year" json:"year" binding:"max=4"`
|
||||||
|
Resolution string `gorm:"column:resolution;varchar(20)" form:"resolution" json:"resolution" binding:"max=20"`
|
||||||
|
Source string `gorm:"column:source;varchar(20)" form:"source" json:"source" binding:"max=20"`
|
||||||
|
HDR string `gorm:"column:hdr;varchar(20)" form:"hdr" json:"hdr" binding:"max=20"`
|
||||||
|
TorrentURL string `gorm:"column:torrenturl;varchar(20);not null" form:"torrenturl" json:"torrenturl" binding:"max=20"`
|
||||||
Won bool `gorm:"column:won;bool" form:"won" json:"won"`
|
Won bool `gorm:"column:won;bool" form:"won" json:"won"`
|
||||||
|
PreRace bool `gorm:"column:prerace;bool" form:"prerace" json:"prerace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRace() *Race {
|
func NewRace() *Race {
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"git.rouggy.com/rouggy/RaceBot/internal/domain"
|
"git.rouggy.com/rouggy/RaceBot/internal/domain"
|
||||||
|
"git.rouggy.com/rouggy/RaceBot/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@ -24,7 +27,7 @@ func (s *Server) Start(cfg *domain.Config) {
|
|||||||
|
|
||||||
s.listener, _ = net.ListenTCP("tcp", tcpAddr)
|
s.listener, _ = net.ListenTCP("tcp", tcpAddr)
|
||||||
|
|
||||||
fmt.Println("[Server] Server is running on port", cfg.Port)
|
log.Printf("[Server] Server is running on %v:%v", cfg.Host, cfg.Port)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
s.Conn, _ = s.listener.Accept()
|
s.Conn, _ = s.listener.Accept()
|
||||||
@ -33,6 +36,13 @@ func (s *Server) Start(cfg *domain.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleRequest() {
|
func (s *Server) handleRequest() {
|
||||||
|
|
||||||
|
r := models.NewRace()
|
||||||
|
d := json.NewDecoder(s.Conn)
|
||||||
|
|
||||||
|
err := d.Decode(&r)
|
||||||
|
log.Println(r, err)
|
||||||
|
|
||||||
//we make a buffer to hold the incoming data.
|
//we make a buffer to hold the incoming data.
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
|
|
||||||
@ -43,10 +53,7 @@ func (s *Server) handleRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print the message to the console.
|
// Print the message to the console.
|
||||||
fmt.Println("Received data:", string(buf[:reqLen]))
|
log.Println(string(buf[:reqLen]))
|
||||||
|
|
||||||
// Write a response back to the client.
|
|
||||||
s.Conn.Write([]byte("Message received."))
|
|
||||||
|
|
||||||
// Close the connection when you're done with it.
|
// Close the connection when you're done with it.
|
||||||
s.Conn.Close()
|
s.Conn.Close()
|
||||||
|
Reference in New Issue
Block a user