Fix tests and linters

This commit is contained in:
Daniel
2022-02-02 12:48:42 +01:00
parent f2fcad4d11
commit 60d8664e7b
171 changed files with 944 additions and 874 deletions

View File

@@ -2,6 +2,7 @@ package ui
import (
resources "github.com/cookieo9/resources-go"
"github.com/safing/portbase/api"
"github.com/safing/portbase/log"
)

View File

@@ -2,18 +2,11 @@ package ui
import (
"github.com/safing/portbase/dataroot"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
)
const (
eventReload = "reload"
)
var (
module *modules.Module
)
var module *modules.Module
func init() {
module = modules.Register("ui", prep, start, nil, "api", "updates")
@@ -36,7 +29,7 @@ func start() error {
// may seem dangerous, but proper permission on the parent directory provide
// (some) protection.
// Processes must _never_ read from this directory.
err := dataroot.Root().ChildDir("exec", 0777).Ensure()
err := dataroot.Root().ChildDir("exec", 0o0777).Ensure()
if err != nil {
log.Warningf("ui: failed to create safe exec dir: %s", err)
}

View File

@@ -1,6 +1,7 @@
package ui
import (
"errors"
"fmt"
"io"
"net/http"
@@ -94,7 +95,7 @@ func (bs *bundleServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// get file from update system
zipFile, err := updates.GetFile(fmt.Sprintf("ui/modules/%s.zip", moduleName))
if err != nil {
if err == updater.ErrNotFound {
if errors.Is(err, updater.ErrNotFound) {
log.Tracef("ui: requested module %s does not exist", moduleName)
http.Error(w, err.Error(), http.StatusNotFound)
} else {
@@ -124,7 +125,7 @@ func (bs *bundleServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func ServeFileFromBundle(w http.ResponseWriter, r *http.Request, bundleName string, bundle *resources.BundleSequence, path string) {
readCloser, err := bundle.Open(path)
if err != nil {
if err == resources.ErrNotFound {
if errors.Is(err, resources.ErrNotFound) {
// Check if there is a base index.html file we can serve instead.
var indexErr error
path = "index.html"
@@ -164,7 +165,7 @@ func ServeFileFromBundle(w http.ResponseWriter, r *http.Request, bundleName stri
}
}
readCloser.Close()
_ = readCloser.Close()
}
// redirectToDefault redirects the request to the default UI module.