Skip to content

Commit

Permalink
Add linter (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed May 7, 2023
1 parent d8f20db commit dbc6c05
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Lint
on:
push:
jobs:
lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
5 changes: 4 additions & 1 deletion controllers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ func SetupRouter() {
}

func runServer(router *gin.Engine) {
router.Run(":8080")
err := router.Run(":8080")
if err != nil {
panic(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..."})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/RomManager/server

go 1.19
go 1.20

require github.com/goccy/go-json v0.10.2 // indirec

Expand Down
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
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
)

func main() {
RunServer()
}

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

Expand Down
20 changes: 14 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 {
return 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,7 +65,11 @@ 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
}
Expand Down

0 comments on commit dbc6c05

Please sign in to comment.