Skip to content

Commit

Permalink
fix most linter warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
packruler committed Oct 23, 2024
1 parent 47a1ea9 commit 692608e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
39 changes: 19 additions & 20 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
run:
timeout: 3m
skip-files:
- httputil/header/header.go
- apps/app_name.go
- themes/theme_name.go
skip-dirs: []
linters-settings:
govet:
check-shadowing: false
golint:
min-confidence: 0
depguard:
rules:
allow_repos:
allow:
- github.com/packruler/rewrite-body/handler
- github.com/packruler/rewrite-body/compressutil
- bytes
- context
- fmt
- net/http
- net/http/httptest
- regexp
- strconv
- strings
- testing
gocyclo:
min-complexity: 12
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 4
Expand All @@ -25,22 +29,13 @@ linters-settings:
linters:
enable-all: true
disable:
- scopelint
- golint
- interfacer
- maligned
- bodyclose
- goerr113
- wrapcheck
- maligned
- exhaustivestruct
- testpackage
- paralleltest
- tparallel
- nosnakecase
issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- don't use an underscore in package name
Expand All @@ -57,3 +52,7 @@ issues:
- path: themepark.go
linters:
- exhaustruct
exclude-files:
- httputil/header/header.go
- apps/app_name.go
- themes/theme_name.go
32 changes: 17 additions & 15 deletions themepark.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,33 @@ func (config *Config) setDefaults() {
}

if config.Theme == "" || config.Theme == "base" {
config.Theme = fmt.Sprintf("%s-base", config.App)
config.Theme = config.App + "-base"
}

if config.Target == "" {
config.Target = config.getRegexTarget()
}
}

var bodyBasedAppsList []string = []string{
"vuetorrent",
"qbittorrent",
"emby",
"jellyfin",
"radarr",
"prowlarr",
"sonarr",
"readarr",
"lidarr",
"whisparr",
}
func getBodyBasedAppsRegex() string {
bodyBasedAppsList := []string{
"vuetorrent",
"qbittorrent",
"emby",
"jellyfin",
"radarr",
"prowlarr",
"sonarr",
"readarr",
"lidarr",
"whisparr",
}

var bodyBasedApps string = "(?i)" + strings.Join(bodyBasedAppsList, "|")
return "(?i)" + strings.Join(bodyBasedAppsList, "|")
}

func (config *Config) getRegexTarget() string {
match, _ := regexp.Match(bodyBasedApps, []byte(config.App))
match, _ := regexp.MatchString(getBodyBasedAppsRegex(), config.App)
if match {
return "</body>"
}
Expand Down
4 changes: 2 additions & 2 deletions themepark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func TestServeHTTP(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
config := test.config

next := func(responseWriter http.ResponseWriter, req *http.Request) {
next := func(responseWriter http.ResponseWriter, _ *http.Request) {
responseWriter.Header().Set("Content-Encoding", test.contentEncoding)
responseWriter.Header().Set("Content-Type", test.contentType)
responseWriter.Header().Set("Content-Length", strconv.Itoa(len(test.resBody)))
responseWriter.WriteHeader(http.StatusOK)

_, _ = fmt.Fprintf(responseWriter, test.resBody)
_, _ = fmt.Fprintf(responseWriter, "%s", test.resBody)
}

rewriteBody, err := New(context.Background(), http.HandlerFunc(next), &config, "rewriteBody")
Expand Down

0 comments on commit 692608e

Please sign in to comment.