Skip to content

Commit

Permalink
fixed linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvodi committed Aug 28, 2024
1 parent 7136c21 commit b04f965
Show file tree
Hide file tree
Showing 23 changed files with 77 additions and 96 deletions.
8 changes: 4 additions & 4 deletions cmd/limepipes-cli/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tomvodi/limepipes/cmd/limepipes-cli/import_type"
"github.com/tomvodi/limepipes/cmd/limepipes-cli/importtype"
"io/fs"
"os"
"path/filepath"
Expand All @@ -20,9 +20,9 @@ var (

func addImportFileTypes(cmd *cobra.Command) {

cmd.Flags().StringSliceVarP(&importTypes, "import-file-types", "i", []string{import_type.BWW.String()},
cmd.Flags().StringSliceVarP(&importTypes, "import-file-types", "i", []string{importtype.BWW.String()},
fmt.Sprintf("only import files of a specific type. Can be specified with a comma separated list like "+
"-i=bww,xml. Valid file types are (%s).", strings.Join(import_type.TypeStrings(), ", ")),
"-i=bww,xml. Valid file types are (%s).", strings.Join(importtype.TypeStrings(), ", ")),
)
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func hasInvalidImportTypes() []string {
var invalidImportTypes []string
for _, importType := range importTypes {
isValidImportType := false
for _, allImportType := range import_type.TypeStrings() {
for _, allImportType := range importtype.TypeStrings() {
if allImportType == importType {
isValidImportType = true
break
Expand Down
34 changes: 17 additions & 17 deletions cmd/limepipes-cli/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/tomvodi/limepipes/internal/config"
"github.com/tomvodi/limepipes/internal/database"
"github.com/tomvodi/limepipes/internal/interfaces"
"github.com/tomvodi/limepipes/internal/plugin_loader"
"github.com/tomvodi/limepipes/internal/pluginloader"
"github.com/tomvodi/limepipes/internal/utils"
"gorm.io/gorm"
"os"
Expand All @@ -30,14 +30,14 @@ subdirectories when given the recursive flag.
If a given file that has an extension which is not in the import-file-types, it will be ignored.
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
utils.SetupConsoleLogger()
cfg, err := config.Init()
if err != nil {
return fmt.Errorf("failed init configuration: %s", err.Error())
}

pluginLoader := plugin_loader.NewPluginLoader()
pluginLoader := pluginloader.NewPluginLoader()
err = pluginLoader.LoadPluginsFromDir(cfg.PluginsDirectoryPath)
if err != nil {
log.Fatal().Err(err).Msg("failed loading plugins")
Expand Down Expand Up @@ -77,9 +77,9 @@ If a given file that has an extension which is not in the import-file-types, it
if skipFailedFiles {
log.Error().Err(err).Msgf("import file %s does not have an extension", file)
continue
} else {
return err
}

return err
}

filePlugin, err := pluginLoader.PluginForFileExtension(".bww")
Expand All @@ -88,19 +88,19 @@ If a given file that has an extension which is not in the import-file-types, it
log.Error().Err(err).Msgf("failed getting plugin for file %s with extension %s",
file, fExt)
continue
} else {
return err
}

return err
}

fileData, err := os.ReadFile(file)
if err != nil {
if skipFailedFiles {
log.Error().Err(err).Msgf("failed reading file %s", file)
continue
} else {
return err
}

return err
}

log.Info().Msgf("importing file %d/%d %s", i+1, allFileCnt, file)
Expand All @@ -110,9 +110,9 @@ If a given file that has an extension which is not in the import-file-types, it
if skipFailedFiles {
log.Error().Err(err).Msgf("failed parsing file %s", file)
continue
} else {
return fmt.Errorf("failed parsing file %s: %v", file, err)
}

return fmt.Errorf("failed parsing file %s: %v", file, err)
}

if verbose {
Expand All @@ -130,29 +130,29 @@ If a given file that has an extension which is not in the import-file-types, it
log.Error().Err(err).Msgf("failed getting file type for file %s with extension %s",
file, fExt)
continue
} else {
return err
}

return err
}

fInfo, err := common.NewImportFileInfoFromLocalFile(file, fType)
if err != nil {
if skipFailedFiles {
log.Error().Err(err).Msg("failed creating import file info")
continue
} else {
return err
}

return err
}

_, _, err = dbService.ImportTunes(tunesImport.ImportedTunes, fInfo)
if err != nil {
if skipFailedFiles {
log.Error().Err(err).Msg("failed importing tunes")
continue
} else {
return fmt.Errorf("failed importing tunes: %s", err.Error())
}

return fmt.Errorf("failed importing tunes: %s", err.Error())
}
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/limepipes-cli/cmd/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/tomvodi/limepipes/internal/config"
"github.com/tomvodi/limepipes/internal/interfaces"
"github.com/tomvodi/limepipes/internal/plugin_loader"
"github.com/tomvodi/limepipes/internal/pluginloader"
"github.com/tomvodi/limepipes/internal/utils"
"os"
"path/filepath"
Expand All @@ -27,7 +27,7 @@ var parserCmd = &cobra.Command{
When given directory paths, it will import all files of that directory. It will also include
subdirectories when given the recursive flag.
If a given file that has an extension which is not in the import-file-types, it will be ignored.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
utils.SetupConsoleLogger()
err := checkForInvalidImportTypes()
if err != nil {
Expand All @@ -39,7 +39,7 @@ If a given file that has an extension which is not in the import-file-types, it
return fmt.Errorf("failed init configuration: %s", err.Error())
}

pluginLoader := plugin_loader.NewPluginLoader()
pluginLoader := pluginloader.NewPluginLoader()
err = pluginLoader.LoadPluginsFromDir(cfg.PluginsDirectoryPath)
if err != nil {
log.Fatal().Err(err).Msg("failed loading plugins")
Expand Down Expand Up @@ -98,9 +98,9 @@ If a given file that has an extension which is not in the import-file-types, it
if skipFailedFiles {
log.Error().Err(err).Msgf("failed parsing file %s", file)
continue
} else {
return fmt.Errorf("failed parsing file %s: %v", file, err)
}

return fmt.Errorf("failed parsing file %s: %v", file, err)
}

if err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package import_type
package importtype

//go:generate go run github.com/dmarkham/enumer -type=Type -transform=snake

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/limepipes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/tomvodi/limepipes/internal/database"
"github.com/tomvodi/limepipes/internal/health"
"github.com/tomvodi/limepipes/internal/interfaces"
"github.com/tomvodi/limepipes/internal/plugin_loader"
"github.com/tomvodi/limepipes/internal/pluginloader"
"github.com/tomvodi/limepipes/internal/utils"
"gorm.io/gorm"
)
Expand All @@ -35,7 +35,7 @@ func main() {
log.Fatal().Err(err).Msg("failed init configuration")
}

pluginLoader := plugin_loader.NewPluginLoader()
pluginLoader := pluginloader.NewPluginLoader()
err = pluginLoader.LoadPluginsFromDir(cfg.PluginsDirectoryPath)
if err != nil {
log.Fatal().Err(err).Msg("failed loading plugins")
Expand Down Expand Up @@ -73,6 +73,6 @@ func main() {
},
)

log.Info().Msgf("listening on %s", cfg.ServerUrl)
log.Fatal().Err(router.RunTLS(cfg.ServerUrl, cfg.TlsCertPath, cfg.TlsCertKeyPath))
log.Info().Msgf("listening on %s", cfg.ServerURL)
log.Fatal().Err(router.RunTLS(cfg.ServerURL, cfg.TLSCertPath, cfg.TLSCertKeyPath))
}
2 changes: 1 addition & 1 deletion internal/api/api_model_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (v *apiModelValidator) ValidateUpdateSet(setUpd apimodel.UpdateSet) error {

func NewAPIModelValidator(
validator *validator.Validate,
) interfaces.ApiModelValidator {
) interfaces.APIModelValidator {
return &apiModelValidator{
validator: validator,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package config

type Config struct {
ServerUrl string `mapstructure:"API_SERVER_URL"`
ServerURL string `mapstructure:"API_SERVER_URL"`

TlsCertPath string `mapstructure:"TLS_CERT_PATH"`
TlsCertKeyPath string `mapstructure:"TLS_CERT_KEY_PATH"`
TLSCertPath string `mapstructure:"TLS_CERT_PATH"`
TLSCertKeyPath string `mapstructure:"TLS_CERT_KEY_PATH"`

DbHost string `mapstructure:"DB_HOST"`
DbPort string `mapstructure:"DB_PORT"`
Expand Down
12 changes: 6 additions & 6 deletions internal/database/db_data_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

type dbService struct {
db *gorm.DB
validator interfaces.ApiModelValidator
validator interfaces.APIModelValidator
}

func (d *dbService) Tunes() ([]*apimodel.Tune, error) {
Expand All @@ -49,7 +49,7 @@ func (d *dbService) CreateTune(

dbTune := model.Tune{}
if importFile != nil {
dbTune.ImportFileId = importFile.ID
dbTune.ImportFileID = importFile.ID
}
var tuneType *model.TuneType
var err error
Expand All @@ -65,7 +65,7 @@ func (d *dbService) CreateTune(
return &apimodel.Tune{}, fmt.Errorf("could not create db object")
}
if tuneType != nil {
dbTune.TuneTypeId = &tuneType.ID
dbTune.TuneTypeID = &tuneType.ID
}

if err = d.db.Create(&dbTune).Error; err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (d *dbService) UpdateTune(id uuid.UUID, updateTune apimodel.UpdateTune) (*a
if err := mapstructure.Decode(&updateTune, &updateVals); err != nil {
return nil, err
}
updateVals["TuneTypeId"] = tuneType.ID
updateVals["TuneTypeID"] = tuneType.ID
delete(updateVals, "Type")

if err := d.db.Model(t).Updates(updateVals).Error; err != nil {
Expand Down Expand Up @@ -263,7 +263,7 @@ func (d *dbService) CreateMusicSet(

dbSet := model.MusicSet{}
if importFile != nil {
dbSet.ImportFileId = importFile.ID
dbSet.ImportFileID = importFile.ID
}
if err := copier.Copy(&dbSet, &musicSet); err != nil {
return &apimodel.MusicSet{}, fmt.Errorf("could not create db object")
Expand Down Expand Up @@ -903,7 +903,7 @@ func (d *dbService) DeleteFileFromTune(tuneID uuid.UUID, fType file_type.Type) e

func NewDbDataService(
db *gorm.DB,
validator interfaces.ApiModelValidator,
validator interfaces.APIModelValidator,
) interfaces.DataService {
return &dbService{
db: db,
Expand Down
2 changes: 1 addition & 1 deletion internal/database/model/base_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type BaseModel struct {
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid()" copier:"Id"`
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid()" copier:"ID"`
CreatedAt sqltime.Time `gorm:"type:timestamp"`
UpdatedAt sqltime.Time `gorm:"type:timestamp"`
}
2 changes: 1 addition & 1 deletion internal/database/model/music_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type MusicSet struct {
Description string
Creator string
Tunes []Tune `gorm:"many2many:music_set_tunes;constraint:OnUpdate:CASCADE;OnDelete:RESTRICT"`
ImportFileId uuid.UUID
ImportFileID uuid.UUID
}
4 changes: 2 additions & 2 deletions internal/database/model/tune.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import "github.com/google/uuid"
type Tune struct {
BaseModel
Title string
TuneTypeId *uuid.UUID
TuneTypeID *uuid.UUID
TuneType *TuneType
TimeSig string
Composer string
Arranger string
Sets []MusicSet `gorm:"many2many:music_set_tunes;constraint:OnUpdate:CASCADE;"`
Files []*TuneFile `gorm:"constraint:OnDelete:CASCADE;"`
ImportFileId uuid.UUID
ImportFileID uuid.UUID
}
19 changes: 0 additions & 19 deletions internal/exporter/musicxml/musicxml_exporter.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (h *healthCheck) init() error {
},
),
healthlib.WithStatusListener(
func(ctx context.Context, state healthlib.CheckerState) {
func(_ context.Context, state healthlib.CheckerState) {
log.Info().Msgf(
fmt.Sprintf("health status changed to %s", state.Status),
)
Expand Down
2 changes: 1 addition & 1 deletion internal/interfaces/api_model_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package interfaces

import "github.com/tomvodi/limepipes/internal/apigen/apimodel"

type ApiModelValidator interface {
type APIModelValidator interface {
ValidateUpdateTune(tuneUpd apimodel.UpdateTune) error
ValidateUpdateSet(tuneUpd apimodel.UpdateSet) error
}
2 changes: 1 addition & 1 deletion internal/interfaces/api_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package interfaces

import "github.com/gin-gonic/gin"

type ApiRouter interface {
type APIRouter interface {
GetEngine() *gin.Engine
}
10 changes: 5 additions & 5 deletions internal/interfaces/data_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ type DataService interface {
UpdateTune(id uuid.UUID, tune apimodel.UpdateTune) (*apimodel.Tune, error)
DeleteTune(id uuid.UUID) error

AddFileToTune(tuneId uuid.UUID, tFile *model.TuneFile) error
DeleteFileFromTune(tuneId uuid.UUID, fType file_type.Type) error
GetTuneFile(tuneId uuid.UUID, fType file_type.Type) (*model.TuneFile, error)
GetTuneFiles(tuneId uuid.UUID) ([]*model.TuneFile, error)
AddFileToTune(tuneID uuid.UUID, tFile *model.TuneFile) error
DeleteFileFromTune(tuneID uuid.UUID, fType file_type.Type) error
GetTuneFile(tuneID uuid.UUID, fType file_type.Type) (*model.TuneFile, error)
GetTuneFiles(tuneID uuid.UUID) ([]*model.TuneFile, error)

MusicSets() ([]*apimodel.MusicSet, error)
CreateMusicSet(tune apimodel.CreateSet, importFile *model.ImportFile) (*apimodel.MusicSet, error)
GetMusicSet(id uuid.UUID) (*apimodel.MusicSet, error)
UpdateMusicSet(id uuid.UUID, tune apimodel.UpdateSet) (*apimodel.MusicSet, error)
DeleteMusicSet(id uuid.UUID) error

AssignTunesToMusicSet(setId uuid.UUID, tuneIds []uuid.UUID) (*apimodel.MusicSet, error)
AssignTunesToMusicSet(setID uuid.UUID, tuneIDs []uuid.UUID) (*apimodel.MusicSet, error)

GetImportFileByHash(fHash string) (*model.ImportFile, error)
ImportTunes(
Expand Down
Loading

0 comments on commit b04f965

Please sign in to comment.