Fix linting errors
This commit is contained in:
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
@@ -16,9 +16,7 @@ const (
|
||||
apiShutdownEndpoint = "core/shutdown"
|
||||
)
|
||||
|
||||
var (
|
||||
httpApiClient *http.Client
|
||||
)
|
||||
var httpAPIClient *http.Client
|
||||
|
||||
func init() {
|
||||
// Make cookie jar.
|
||||
@@ -29,22 +27,22 @@ func init() {
|
||||
}
|
||||
|
||||
// Create client.
|
||||
httpApiClient = &http.Client{
|
||||
httpAPIClient = &http.Client{
|
||||
Jar: jar,
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
func httpApiAction(endpoint string) (response string, err error) {
|
||||
func httpAPIAction(endpoint string) (response string, err error) {
|
||||
// Make action request.
|
||||
resp, err := httpApiClient.Post(apiBaseURL+endpoint, "", nil)
|
||||
resp, err := httpAPIClient.Post(apiBaseURL+endpoint, "", nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
|
||||
// Read the response body.
|
||||
defer resp.Body.Close()
|
||||
respData, err := ioutil.ReadAll(resp.Body)
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
respData, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read data: %w", err)
|
||||
}
|
||||
@@ -60,6 +58,6 @@ func httpApiAction(endpoint string) (response string, err error) {
|
||||
|
||||
// TriggerShutdown triggers a shutdown via the APi.
|
||||
func TriggerShutdown() error {
|
||||
_, err := httpApiAction(apiShutdownEndpoint)
|
||||
_, err := httpAPIAction(apiShutdownEndpoint)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func ensureAppIcon() (location string, err error) {
|
||||
if appIconPath == "" {
|
||||
appIconPath = filepath.Join(dataDir, "exec", "portmaster.png")
|
||||
}
|
||||
err = os.WriteFile(appIconPath, icons.PNG, 0o0644)
|
||||
err = os.WriteFile(appIconPath, icons.PNG, 0o0644) // nolint:gosec
|
||||
})
|
||||
|
||||
return appIconPath, err
|
||||
|
||||
@@ -52,6 +52,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
const query = "query "
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&dataDir, "data", "", "set data directory")
|
||||
flag.BoolVar(&printStackOnExit, "print-stack-on-exit", false, "prints the stack before of shutting down")
|
||||
|
||||
@@ -14,7 +14,7 @@ type Notification struct {
|
||||
systemID NotificationID
|
||||
}
|
||||
|
||||
// IsSupported returns whether the action is supported on this system.
|
||||
// IsSupportedAction returns whether the action is supported on this system.
|
||||
func IsSupportedAction(a pbnotify.Action) bool {
|
||||
switch a.Type {
|
||||
case pbnotify.ActionTypeNone:
|
||||
@@ -26,11 +26,10 @@ func IsSupportedAction(a pbnotify.Action) bool {
|
||||
|
||||
// SelectAction sends an action back to the portmaster.
|
||||
func (n *Notification) SelectAction(action string) {
|
||||
new := &pbnotify.Notification{
|
||||
upd := &pbnotify.Notification{
|
||||
EventID: n.EventID,
|
||||
SelectedActionID: action,
|
||||
}
|
||||
|
||||
// FIXME: check response
|
||||
apiClient.Update(fmt.Sprintf("%s%s", dbNotifBasePath, new.EventID), new, nil)
|
||||
_ = apiClient.Update(fmt.Sprintf("%s%s", dbNotifBasePath, upd.EventID), upd, nil)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/safing/portbase/api/client"
|
||||
"github.com/safing/portbase/formats/dsd"
|
||||
"github.com/safing/portbase/log"
|
||||
|
||||
pbnotify "github.com/safing/portbase/notifications"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
notify "github.com/dhaavi/go-notify"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
)
|
||||
|
||||
@@ -45,7 +47,12 @@ listenForNotifications:
|
||||
continue listenForNotifications
|
||||
}
|
||||
|
||||
notification := n.(*Notification)
|
||||
notification, ok := n.(*Notification)
|
||||
if !ok {
|
||||
log.Errorf("received invalid notification type %T", n)
|
||||
|
||||
continue listenForNotifications
|
||||
}
|
||||
|
||||
log.Tracef("notify: received signal: %+v", sig)
|
||||
if sig.ActionKey != "" {
|
||||
@@ -62,7 +69,6 @@ listenForNotifications:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func actionListener() {
|
||||
@@ -71,7 +77,7 @@ func actionListener() {
|
||||
go handleActions(mainCtx, actions)
|
||||
|
||||
err := notify.SignalNotify(mainCtx, actions)
|
||||
if err != nil && err != context.Canceled {
|
||||
if err != nil && errors.Is(err, context.Canceled) {
|
||||
log.Errorf("notify: signal listener failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/tevino/abool"
|
||||
|
||||
"github.com/safing/portbase/api/client"
|
||||
"github.com/safing/portbase/formats/dsd"
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/tevino/abool"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,10 +49,10 @@ func updateSPNStatus(s *SPNStatus) {
|
||||
}
|
||||
|
||||
func spnStatusClient() {
|
||||
moduleQueryOp := apiClient.Qsub("query "+spnModuleKey, handleSPNModuleUpdate)
|
||||
moduleQueryOp := apiClient.Qsub(query+spnModuleKey, handleSPNModuleUpdate)
|
||||
moduleQueryOp.EnableResuscitation()
|
||||
|
||||
statusQueryOp := apiClient.Qsub("query "+spnStatusKey, handleSPNStatusUpdate)
|
||||
statusQueryOp := apiClient.Qsub(query+spnStatusKey, handleSPNStatusUpdate)
|
||||
statusQueryOp.EnableResuscitation()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/safing/portbase/api/client"
|
||||
@@ -14,7 +13,7 @@ const (
|
||||
|
||||
// Module Failure Status Values
|
||||
// FailureNone = 0 // unused
|
||||
// FailureHint = 1 // unused
|
||||
// FailureHint = 1 // unused.
|
||||
FailureWarning = 2
|
||||
FailureError = 3
|
||||
)
|
||||
@@ -92,7 +91,7 @@ func clearSubsystems() {
|
||||
}
|
||||
|
||||
func subsystemsClient() {
|
||||
subsystemsOp := apiClient.Qsub(fmt.Sprintf("query %s", subsystemsKeySpace), handleSubsystem)
|
||||
subsystemsOp := apiClient.Qsub("query "+subsystemsKeySpace, handleSubsystem)
|
||||
subsystemsOp.EnableResuscitation()
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ func onReady() {
|
||||
}
|
||||
|
||||
func onExit() {
|
||||
|
||||
}
|
||||
|
||||
func triggerTrayUpdate() {
|
||||
@@ -172,7 +171,7 @@ func updateTray() {
|
||||
// Set SPN status if changed.
|
||||
if spnStatus != nil && activeSPNStatus != spnStatus.Status {
|
||||
activeSPNStatus = spnStatus.Status
|
||||
menuItemSPNStatus.SetTitle("SPN: " + strings.Title(activeSPNStatus))
|
||||
menuItemSPNStatus.SetTitle("SPN: " + strings.Title(activeSPNStatus)) // nolint:staticcheck
|
||||
}
|
||||
|
||||
// Set SPN switch if changed.
|
||||
|
||||
@@ -79,7 +79,7 @@ func createInstanceLock(lockFilePath string) error {
|
||||
|
||||
// create lock file
|
||||
// TODO: Investigate required permissions.
|
||||
err = os.WriteFile(lockFilePath, []byte(fmt.Sprintf("%d", os.Getpid())), 0o0666) //nolint:gosec
|
||||
err = os.WriteFile(lockFilePath, []byte(strconv.Itoa(os.Getpid())), 0o0666) //nolint:gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user