Skip to content

Commit

Permalink
simplified scanner, mockfs, scanner tests, multiple folders support (#…
Browse files Browse the repository at this point in the history
…167)

* refactor: update scanner, scanner tests, mockfs

closes #165
closes #163

* feat: add multi folder support

closes #50

* chore: upgrade deps
  • Loading branch information
sentriz committed Nov 7, 2021
1 parent b07b9a8 commit fdd4dd8
Show file tree
Hide file tree
Showing 72 changed files with 4,289 additions and 2,711 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly-release.yaml
@@ -1,7 +1,7 @@
name: Nightly Release
on:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"
workflow_dispatch: {}
jobs:
test:
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.0
version: v1.42.1
skip-go-installation: true
- name: Test
run: go test ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.0
version: v1.42.1
skip-go-installation: true
- name: Test
run: go test ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.0
version: v1.42.1
skip-go-installation: true
- name: Test
run: go test ./...
86 changes: 40 additions & 46 deletions .golangci.yml
@@ -1,57 +1,51 @@
run:
skip-dirs:
- server/assets
- server/assets
skip-dirs-use-default: true

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exportloopref
- gochecknoglobals
- gochecknoinits
- goconst
- gocritic
- gocyclo
- goerr113
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- varcheck

issues:
exclude-rules:
- path: _test\.go
linters:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exportloopref
- gochecknoglobals
- text: "weak cryptographic primitive"
linters:
- gosec
- text: "weak random number generator"
linters:
- gochecknoinits
- goconst
- gocritic
- gocyclo
- goerr113
- goprintffuncname
- gosec

# TODO: fix these
- text: "should have comment"
linters:
- golint
- text: "at least one file in a package should have a package comment"
linters:
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- varcheck

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gochecknoglobals
- text: "weak cryptographic primitive"
linters:
- gosec
- text: "weak random number generator"
linters:
- gosec
- text: "at least one file in a package should have a package comment"
linters:
- stylecheck
45 changes: 35 additions & 10 deletions cmd/gonic/gonic.go
Expand Up @@ -30,7 +30,6 @@ const (
func main() {
set := flag.NewFlagSet(gonic.Name, flag.ExitOnError)
confListenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
confMusicPath := set.String("music-path", "", "path to music")
confPodcastPath := set.String("podcast-path", "", "path to podcasts")
confCachePath := set.String("cache-path", "", "path to cache")
confDBPath := set.String("db-path", "gonic.db", "path to database (optional)")
Expand All @@ -40,6 +39,10 @@ func main() {
confGenreSplit := set.String("genre-split", "\n", "character or string to split genre tag data on (optional)")
confHTTPLog := set.Bool("http-log", true, "http request logging (optional)")
confShowVersion := set.Bool("version", false, "show gonic version")

var confMusicPaths musicPaths
set.Var(&confMusicPaths, "music-path", "path to music")

_ = set.String("config-path", "", "path to config (optional)")

if err := ff.Parse(set, os.Args[1:],
Expand All @@ -62,8 +65,13 @@ func main() {
log.Printf(" %-15s %s\n", f.Name, value)
})

if _, err := os.Stat(*confMusicPath); os.IsNotExist(err) {
log.Fatal("please provide a valid music directory")
if len(confMusicPaths) == 0 {
log.Fatalf("please provide a music directory")
}
for _, confMusicPath := range confMusicPaths {
if _, err := os.Stat(confMusicPath); os.IsNotExist(err) {
log.Fatalf("music directory %q not found", confMusicPath)
}
}
if _, err := os.Stat(*confPodcastPath); os.IsNotExist(err) {
log.Fatal("please provide a valid podcast directory")
Expand All @@ -86,17 +94,24 @@ func main() {
}
}

db, err := db.New(*confDBPath)
dbc, err := db.New(*confDBPath, db.DefaultOptions())
if err != nil {
log.Fatalf("error opening database: %v\n", err)
}
defer db.Close()
defer dbc.Close()

err = dbc.Migrate(db.MigrationContext{
OriginalMusicPath: confMusicPaths[0],
})
if err != nil {
log.Panicf("error migrating database: %v\n", err)
}

proxyPrefixExpr := regexp.MustCompile(`^\/*(.*?)\/*$`)
*confProxyPrefix = proxyPrefixExpr.ReplaceAllString(*confProxyPrefix, `/$1`)
server, err := server.New(server.Options{
DB: db,
MusicPath: *confMusicPath,
DB: dbc,
MusicPaths: confMusicPaths,
CachePath: cacheDirAudio,
CoverCachePath: cacheDirCovers,
ProxyPrefix: *confProxyPrefix,
Expand All @@ -106,8 +121,7 @@ func main() {
JukeboxEnabled: *confJukeboxEnabled,
})
if err != nil {
log.Printf("error creating server: %v\n", err)
return
log.Panicf("error creating server: %v\n", err)
}

var g run.Group
Expand All @@ -123,6 +137,17 @@ func main() {
}

if err := g.Run(); err != nil {
log.Printf("error in job: %v", err)
log.Panicf("error in job: %v", err)
}
}

type musicPaths []string

func (m musicPaths) String() string {
return strings.Join(m, ", ")
}

func (m *musicPaths) Set(value string) error {
*m = append(*m, value)
return nil
}
51 changes: 0 additions & 51 deletions gen_handler_tests

This file was deleted.

40 changes: 20 additions & 20 deletions go.mod
Expand Up @@ -3,41 +3,41 @@ module go.senan.xyz/gonic
go 1.16

require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/cespare/xxhash v1.1.0
github.com/disintegration/imaging v1.6.2
github.com/dustin/go-humanize v1.0.0
github.com/faiface/beep v1.0.3-0.20210817042730-1c98bf641535
github.com/google/uuid v1.1.2 // indirect
github.com/gopherjs/gopherwasm v1.0.0 // indirect
github.com/faiface/beep v1.1.0
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/gorilla/securecookie v1.1.1
github.com/gorilla/sessions v1.2.1
github.com/hajimehoshi/go-mp3 v0.3.1 // indirect
github.com/hajimehoshi/go-mp3 v0.3.2 // indirect
github.com/hajimehoshi/oto v1.0.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jinzhu/gorm v1.9.16
github.com/josephburnett/jd v0.0.0-20191228205456-aa1a7c66b42f
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.16.1
github.com/kr/pretty v0.1.0 // indirect
github.com/mewkiz/pkg v0.0.0-20200702171441-dd47075182ea // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/mmcdole/gofeed v1.1.0
github.com/matryer/is v1.4.0
github.com/mewkiz/pkg v0.0.0-20211102230744-16a6ce8f1b77 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mmcdole/gofeed v1.1.3
github.com/mmcdole/goxpp v0.0.0-20200921145534-2f3784f67354 // indirect
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd
github.com/oklog/run v1.1.0
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
github.com/peterbourgon/ff v1.7.0
github.com/pkg/errors v0.9.1 // indirect
github.com/peterbourgon/ff v1.7.1
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
github.com/wader/gormstore v0.0.0-20200328121358-65a111a20c23
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/exp v0.0.0-20201229011636-eab1b5eb1a03 // indirect
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/wader/gormstore v0.0.0-20211009162750-8bf4f5606ef4
golang.org/x/exp v0.0.0-20211103171733-83d51122435b // indirect
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/mobile v0.0.0-20211103151657-e68c98865fb2 // indirect
golang.org/x/net v0.0.0-20211104170005-ce137452f963 // indirect
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
gopkg.in/gormigrate.v1 v1.6.0
)

0 comments on commit fdd4dd8

Please sign in to comment.