Merge pull request #187 from safing/maintain/small-fixes

Small fixes and improvements
This commit is contained in:
Daniel Hovie 2022-09-22 16:37:36 +02:00 committed by GitHub
commit 85a84c1210
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 23 deletions

View file

@ -20,14 +20,14 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
go-version: '^1.19'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.45.1
version: v1.49.0
only-new-issues: true
args: -c ./.golangci.yml
args: -c ./.golangci.yml --timeout 15m
- name: Get dependencies
run: go mod download
@ -45,7 +45,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '^1.18'
go-version: '^1.19'
- name: Get dependencies
run: go mod download

View file

@ -8,6 +8,7 @@ linters:
- contextcheck
- cyclop
- exhaustivestruct
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
@ -17,6 +18,7 @@ linters:
- goerr113
- gomnd
- ifshort
- interfacebloat
- interfacer
- ireturn
- lll
@ -24,6 +26,9 @@ linters:
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosnakecase
- revive
- tagliatelle
- testpackage
@ -31,7 +36,6 @@ linters:
- whitespace
- wrapcheck
- wsl
- nolintlint
linters-settings:
revive:

View file

@ -82,7 +82,7 @@ func startDatabaseAPI(w http.ResponseWriter, r *http.Request) {
if err != nil {
errMsg := fmt.Sprintf("could not upgrade: %s", err)
log.Error(errMsg)
http.Error(w, errMsg, 400)
http.Error(w, errMsg, http.StatusBadRequest)
return
}

View file

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"runtime/pprof"
"strings"
"time"
"github.com/safing/portbase/utils/debug"
@ -48,7 +49,12 @@ func registerDebugEndpoints() error {
Read: PermitAnyone,
DataFunc: handleCPUProfile,
Name: "Get CPU Profile",
Description: "",
Description: strings.ReplaceAll(`Gather and return the CPU profile.
This data needs to gathered over a period of time, which is specified using the duration parameter.
You can easily view this data in your browser with this command (with Go installed):
"go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/cpu"
`, `"`, "`"),
Parameters: []Parameter{{
Method: http.MethodGet,
Field: "duration",
@ -64,7 +70,11 @@ func registerDebugEndpoints() error {
Read: PermitAnyone,
DataFunc: handleHeapProfile,
Name: "Get Heap Profile",
Description: "",
Description: strings.ReplaceAll(`Gather and return the heap memory profile.
You can easily view this data in your browser with this command (with Go installed):
"go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/heap"
`, `"`, "`"),
}); err != nil {
return err
}
@ -74,7 +84,11 @@ func registerDebugEndpoints() error {
Read: PermitAnyone,
DataFunc: handleAllocsProfile,
Name: "Get Allocs Profile",
Description: "",
Description: strings.ReplaceAll(`Gather and return the memory allocation profile.
You can easily view this data in your browser with this command (with Go installed):
"go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/allocs"
`, `"`, "`"),
}); err != nil {
return err
}

View file

@ -23,7 +23,9 @@ var (
mainMux = mux.NewRouter()
// server is the main server.
server = &http.Server{}
server = &http.Server{
ReadHeaderTimeout: 10 * time.Second,
}
handlerLock sync.RWMutex
allowedDevCORSOrigins = []string{

View file

@ -71,6 +71,12 @@ func EnableModuleManagement(changeNotifyFn func(*Module)) bool {
return false
}
// DisableModuleManagement disables module management and returns the module
// system to the default start/stop behavior.
func DisableModuleManagement() {
moduleMgmtEnabled.UnSet()
}
func (m *Module) notifyOfChange() {
if moduleMgmtEnabled.IsSet() && modulesChangeNotifyFn != nil {
m.StartWorker("notify of change", func(ctx context.Context) error {

View file

@ -33,6 +33,7 @@ func Run() int {
// Start
err := modules.Start()
if err != nil {
// Immediately return for a clean exit.
if errors.Is(err, modules.ErrCleanExit) {
return 0
}
@ -41,8 +42,17 @@ func Run() int {
printStackTo(os.Stdout, "PRINTING STACK ON EXIT (STARTUP ERROR)")
}
// Trigger shutdown and wait for it to complete.
_ = modules.Shutdown()
return modules.GetExitStatusCode()
exitCode := modules.GetExitStatusCode()
// Return the exit code, if it was set.
if exitCode > 0 {
return exitCode
}
// Otherwise, return a default 1.
return 1
}
// Shutdown