Skip to content

Commit 1f188a5

Browse files
committed
moved validaiton before start
1 parent 07673b1 commit 1f188a5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

pkg/app/app.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"io"
1616
"log"
17+
"net"
1718
"net/http"
1819
"os"
1920
"sort"
@@ -227,12 +228,17 @@ func (a *App) InitGlobalFlags() {
227228

228229
func (a *App) PreRunE(cmd *cobra.Command, args []string) error {
229230
if a.Config.EnablePprof {
230-
a.pprof.Start(a.Config.GlobalFlags.PprofAddr)
231-
a.Logger.Printf("pprof server started at %s", a.Config.GlobalFlags.PprofAddr)
232-
go func() {
233-
err := <-a.pprof.ErrChan()
234-
a.Logger.Printf("pprof server failed: %v", err)
235-
}()
231+
_, _, err := net.SplitHostPort(a.Config.GlobalFlags.PprofAddr)
232+
if err != nil {
233+
fmt.Printf("pprof error %v", err)
234+
} else {
235+
a.pprof.Start(a.Config.GlobalFlags.PprofAddr)
236+
a.Logger.Printf("pprof server started at %s/debug/pprof", a.Config.GlobalFlags.PprofAddr)
237+
go func() {
238+
err := <-a.pprof.ErrChan()
239+
a.Logger.Printf("pprof server failed: %v", err)
240+
}()
241+
}
236242
}
237243

238244
a.Config.SetGlobalsFromEnv(a.RootCmd)

pkg/app/pprof.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package app
22

33
import (
4-
"fmt"
5-
"net"
64
"net/http"
75
_ "net/http/pprof" //nolint:gosec // Import for pprof, only enabled via CLI flag
86
"time"
@@ -20,12 +18,6 @@ func newPprofServer() *pprofServer {
2018

2119
func (p *pprofServer) Start(address string) {
2220
go func() {
23-
_, _, err := net.SplitHostPort(address)
24-
if err != nil {
25-
fmt.Printf("error %v, using default %q", err, defaultPprofAddr)
26-
address = defaultPprofAddr
27-
}
28-
2921
server := &http.Server{
3022
Addr: address,
3123
ReadHeaderTimeout: 10 * time.Second,

0 commit comments

Comments
 (0)