From 3dac036edf7c7d1df1ef1ad5c9fea643c346e534 Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 20:37:20 -0500 Subject: [PATCH 1/2] Added flag for pprof and debug make target. --- Makefile | 6 +++++- cmd.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7638bec..a6d0826 100644 --- a/Makefile +++ b/Makefile @@ -24,5 +24,9 @@ $(KEY): run: $(BINARY) $(KEY) ./$(BINARY) -i $(KEY) --bind ":$(PORT)" -vv +debug: $(BINARY) $(KEY) + ./$(BINARY) --pprof 6060 -i $(KEY) --bind ":$(PORT)" -vv + + test: - go test . + go test . \ No newline at end of file diff --git a/cmd.go b/cmd.go index 9f5ea84..3bbbc58 100644 --- a/cmd.go +++ b/cmd.go @@ -7,13 +7,16 @@ import ( "os" "os/signal" "strings" + "net/http" "github.com/alexcesaro/log" "github.com/alexcesaro/log/golog" "github.com/jessevdk/go-flags" ) +import _ "net/http/pprof" // Options contains the flag options + type Options struct { Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."` Identity string `short:"i" long:"identity" description:"Private key to identify server with." default:"~/.ssh/id_rsa"` @@ -21,6 +24,7 @@ type Options struct { Admin []string `long:"admin" description:"Fingerprint of pubkey to mark as admin."` Whitelist string `long:"whitelist" description:"Optional file of pubkey fingerprints that are allowed to connect"` Motd string `long:"motd" description:"Message of the Day file (optional)"` + Pprof int `long:"pprof" description:"enable http server for pprof"` } var logLevels = []log.Level{ @@ -32,7 +36,6 @@ var logLevels = []log.Level{ func main() { options := Options{} parser := flags.NewParser(&options, flags.Default) - p, err := parser.Parse() if err != nil { if p == nil { @@ -41,6 +44,12 @@ func main() { return } + if options.Pprof != 0 { + go func(){ + fmt.Println(http.ListenAndServe(fmt.Sprintf("localhost:%d", options.Pprof), nil)) + }() + } + // Initialize seed for random colors RandomColorInit() From e94838dbe85dbe92633b2f8a67020ef04433dcee Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 21:11:20 -0500 Subject: [PATCH 2/2] Should pass golint now --- cmd.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd.go b/cmd.go index 3bbbc58..ab41788 100644 --- a/cmd.go +++ b/cmd.go @@ -16,7 +16,6 @@ import ( import _ "net/http/pprof" // Options contains the flag options - type Options struct { Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."` Identity string `short:"i" long:"identity" description:"Private key to identify server with." default:"~/.ssh/id_rsa"` @@ -24,7 +23,7 @@ type Options struct { Admin []string `long:"admin" description:"Fingerprint of pubkey to mark as admin."` Whitelist string `long:"whitelist" description:"Optional file of pubkey fingerprints that are allowed to connect"` Motd string `long:"motd" description:"Message of the Day file (optional)"` - Pprof int `long:"pprof" description:"enable http server for pprof"` + Pprof int `long:"pprof" description:"enable http server for pprof"` } var logLevels = []log.Level{