mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Merge pull request #187 from safing/maintain/small-fixes
Small fixes and improvements
This commit is contained in:
commit
85a84c1210
7 changed files with 59 additions and 23 deletions
8
.github/workflows/go.yml
vendored
8
.github/workflows/go.yml
vendored
|
@ -20,14 +20,14 @@ jobs:
|
||||||
|
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '^1.18'
|
go-version: '^1.19'
|
||||||
|
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.45.1
|
version: v1.49.0
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
args: -c ./.golangci.yml
|
args: -c ./.golangci.yml --timeout 15m
|
||||||
|
|
||||||
- name: Get dependencies
|
- name: Get dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
@ -45,7 +45,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '^1.18'
|
go-version: '^1.19'
|
||||||
|
|
||||||
- name: Get dependencies
|
- name: Get dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
|
@ -8,6 +8,7 @@ linters:
|
||||||
- contextcheck
|
- contextcheck
|
||||||
- cyclop
|
- cyclop
|
||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
|
- exhaustruct
|
||||||
- forbidigo
|
- forbidigo
|
||||||
- funlen
|
- funlen
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
|
@ -17,6 +18,7 @@ linters:
|
||||||
- goerr113
|
- goerr113
|
||||||
- gomnd
|
- gomnd
|
||||||
- ifshort
|
- ifshort
|
||||||
|
- interfacebloat
|
||||||
- interfacer
|
- interfacer
|
||||||
- ireturn
|
- ireturn
|
||||||
- lll
|
- lll
|
||||||
|
@ -24,6 +26,9 @@ linters:
|
||||||
- nilnil
|
- nilnil
|
||||||
- nlreturn
|
- nlreturn
|
||||||
- noctx
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- nonamedreturns
|
||||||
|
- nosnakecase
|
||||||
- revive
|
- revive
|
||||||
- tagliatelle
|
- tagliatelle
|
||||||
- testpackage
|
- testpackage
|
||||||
|
@ -31,7 +36,6 @@ linters:
|
||||||
- whitespace
|
- whitespace
|
||||||
- wrapcheck
|
- wrapcheck
|
||||||
- wsl
|
- wsl
|
||||||
- nolintlint
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
revive:
|
revive:
|
||||||
|
|
|
@ -82,7 +82,7 @@ func startDatabaseAPI(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := fmt.Sprintf("could not upgrade: %s", err)
|
errMsg := fmt.Sprintf("could not upgrade: %s", err)
|
||||||
log.Error(errMsg)
|
log.Error(errMsg)
|
||||||
http.Error(w, errMsg, 400)
|
http.Error(w, errMsg, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/safing/portbase/utils/debug"
|
"github.com/safing/portbase/utils/debug"
|
||||||
|
@ -44,11 +45,16 @@ func registerDebugEndpoints() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := RegisterEndpoint(Endpoint{
|
if err := RegisterEndpoint(Endpoint{
|
||||||
Path: "debug/cpu",
|
Path: "debug/cpu",
|
||||||
Read: PermitAnyone,
|
Read: PermitAnyone,
|
||||||
DataFunc: handleCPUProfile,
|
DataFunc: handleCPUProfile,
|
||||||
Name: "Get CPU Profile",
|
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{{
|
Parameters: []Parameter{{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Field: "duration",
|
Field: "duration",
|
||||||
|
@ -60,21 +66,29 @@ func registerDebugEndpoints() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := RegisterEndpoint(Endpoint{
|
if err := RegisterEndpoint(Endpoint{
|
||||||
Path: "debug/heap",
|
Path: "debug/heap",
|
||||||
Read: PermitAnyone,
|
Read: PermitAnyone,
|
||||||
DataFunc: handleHeapProfile,
|
DataFunc: handleHeapProfile,
|
||||||
Name: "Get Heap Profile",
|
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 {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := RegisterEndpoint(Endpoint{
|
if err := RegisterEndpoint(Endpoint{
|
||||||
Path: "debug/allocs",
|
Path: "debug/allocs",
|
||||||
Read: PermitAnyone,
|
Read: PermitAnyone,
|
||||||
DataFunc: handleAllocsProfile,
|
DataFunc: handleAllocsProfile,
|
||||||
Name: "Get Allocs Profile",
|
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 {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ var (
|
||||||
mainMux = mux.NewRouter()
|
mainMux = mux.NewRouter()
|
||||||
|
|
||||||
// server is the main server.
|
// server is the main server.
|
||||||
server = &http.Server{}
|
server = &http.Server{
|
||||||
|
ReadHeaderTimeout: 10 * time.Second,
|
||||||
|
}
|
||||||
handlerLock sync.RWMutex
|
handlerLock sync.RWMutex
|
||||||
|
|
||||||
allowedDevCORSOrigins = []string{
|
allowedDevCORSOrigins = []string{
|
||||||
|
|
|
@ -71,6 +71,12 @@ func EnableModuleManagement(changeNotifyFn func(*Module)) bool {
|
||||||
return false
|
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() {
|
func (m *Module) notifyOfChange() {
|
||||||
if moduleMgmtEnabled.IsSet() && modulesChangeNotifyFn != nil {
|
if moduleMgmtEnabled.IsSet() && modulesChangeNotifyFn != nil {
|
||||||
m.StartWorker("notify of change", func(ctx context.Context) error {
|
m.StartWorker("notify of change", func(ctx context.Context) error {
|
||||||
|
|
12
run/main.go
12
run/main.go
|
@ -33,6 +33,7 @@ func Run() int {
|
||||||
// Start
|
// Start
|
||||||
err := modules.Start()
|
err := modules.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Immediately return for a clean exit.
|
||||||
if errors.Is(err, modules.ErrCleanExit) {
|
if errors.Is(err, modules.ErrCleanExit) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -41,8 +42,17 @@ func Run() int {
|
||||||
printStackTo(os.Stdout, "PRINTING STACK ON EXIT (STARTUP ERROR)")
|
printStackTo(os.Stdout, "PRINTING STACK ON EXIT (STARTUP ERROR)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger shutdown and wait for it to complete.
|
||||||
_ = modules.Shutdown()
|
_ = 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
|
// Shutdown
|
||||||
|
|
Loading…
Add table
Reference in a new issue