Skip to content

Commit

Permalink
Add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed May 7, 2023
1 parent d8f20db commit 14d164d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint
on:
push:
jobs:
lint:
name: ESLint & prettier
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.17'
cache: false
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
12 changes: 8 additions & 4 deletions controllers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin"
)

func SetupRouter() {
func SetupRouter() error {
if !config.Config().DebugEnabled {
fmt.Println("Running server in production mode...")
gin.SetMode(gin.ReleaseMode)
Expand Down Expand Up @@ -50,9 +50,13 @@ func SetupRouter() {
// Static files
// public.Static("/files", config.Config().DataPath)

runServer(r)
return runServer(r)
}

func runServer(router *gin.Engine) {
router.Run(":8080")
func runServer(router *gin.Engine) error {
err := router.Run(":8080")
if err != nil {
fmt.Println(err.Error())
}
return err
}
6 changes: 5 additions & 1 deletion controllers/synchronization.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
)

func Sync(c *gin.Context) {
roms.SyncRomFiles()
err := roms.SyncRomFiles()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Error while syncing"})
return
}

c.JSON(http.StatusOK, gin.H{"message": "Started syncing..."})
}
10 changes: 8 additions & 2 deletions gridapi/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func SearchForGame(gameName string) (GameResponse, error) {

dataRes := new(ArrayDataResponse)

UnmarshalData(resp, dataRes)
err = UnmarshalData(resp, dataRes)
if err != nil {
return GameResponse{}, err
}

if len(dataRes.GameArray) == 0 {
return GameResponse{}, nil
Expand All @@ -34,7 +37,10 @@ func GetGameGrid(gameID int) (GridResponse, error) {

dataRes := new(ArrayGridResponse)

UnmarshalData(resp, dataRes)
err = UnmarshalData(resp, dataRes)
if err != nil {
return GridResponse{}, err
}

if len(dataRes.GridArray) == 0 {
return GridResponse{}, nil
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
)

func main() {
RunServer()
err := RunServer()
if err != nil {
fmt.Println(err.Error())
}
}

func RunServer() {
func RunServer() error {
fmt.Println("Welcome to the RomManager server")
fmt.Printf("Loaded config with SteamGridDBEnabled: %v\n", config.Config().GridAPIEnabled)

Expand All @@ -26,5 +29,6 @@ func RunServer() {

// Connect to DB and setup router
models.ConnectDatabase()
controllers.SetupRouter()
err := controllers.SetupRouter()
return err
}
21 changes: 15 additions & 6 deletions roms/synchronization.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func SetupDirectories() {
}

// TODO: Write method for check if files are missing
func SyncRomFiles() {

func SyncRomFiles() error {
dataPath := config.Config().DataPath

if config.Config().DataPath == "data/" {
Expand All @@ -40,13 +39,18 @@ func SyncRomFiles() {
// Iterate through the each emulator folder
for _, emulator := range EmulatorList {
emulatorPath := dataPath + emulator.FolderName
walkThroughDir(emulatorPath, emulator)
err := walkThroughDir(emulatorPath, emulator)
if err != nil {
fmt.Println(err.Error())
return err
}
}
return nil
}

// TODO: Make log process a bit cleaner
func walkThroughDir(path string, emulator Emulator) {
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
func walkThroughDir(path string, emulator Emulator) error {
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
c := color.New(color.FgCyan)
if err != nil {
fmt.Println(err.Error())
Expand All @@ -61,14 +65,19 @@ func walkThroughDir(path string, emulator Emulator) {
// Check if a rom with the filepath already exists; if not -> Save to roms db
if !models.CheckRomExistsByFilepath(path) {
rom := createRom(c, path, info.Name(), emulator.FolderName)
rom.SaveRom()
_, err := rom.SaveRom()
if err != nil {
fmt.Println(err.Error())
return err
}
c.Printf("Didn't find in DB --- Created a new entry --- Continuing...\n")
return nil
}

c.Printf("Found in DB --- Continuing...\n")
return nil
})
return err
}

func createRom(c *color.Color, path string, filename string, emulator string) models.Rom {
Expand Down

0 comments on commit 14d164d

Please sign in to comment.