File tree 3 files changed +12
-12
lines changed
3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,11 @@ type Options struct {
43
43
// Optional.
44
44
Addr string
45
45
46
- // NoShutdownCleanup tells the agent not to automatically cleanup
47
- // resources if the running process receives an interrupt.
46
+ // ShutdownCleanup automatically cleans up resources if the
47
+ // running process receives an interrupt. Otherwise, users
48
+ // can call Close before shutting down.
48
49
// Optional.
49
- NoShutdownCleanup bool
50
+ ShutdownCleanup bool
50
51
}
51
52
52
53
// Listen starts the gops agent on a host process. Once agent started, users
@@ -58,13 +59,10 @@ type Options struct {
58
59
// Note: The agent exposes an endpoint via a TCP connection that can be used by
59
60
// any program on the system. Review your security requirements before starting
60
61
// the agent.
61
- func Listen (opts * Options ) error {
62
+ func Listen (opts Options ) error {
62
63
mu .Lock ()
63
64
defer mu .Unlock ()
64
65
65
- if opts == nil {
66
- opts = & Options {}
67
- }
68
66
if portfile != "" {
69
67
return fmt .Errorf ("gops: agent already listening at: %v" , listener .Addr ())
70
68
}
@@ -77,7 +75,7 @@ func Listen(opts *Options) error {
77
75
if err != nil {
78
76
return err
79
77
}
80
- if ! opts .NoShutdownCleanup {
78
+ if opts .ShutdownCleanup {
81
79
gracefulShutdown ()
82
80
}
83
81
Original file line number Diff line number Diff line change @@ -10,15 +10,15 @@ import (
10
10
)
11
11
12
12
func TestListen (t * testing.T ) {
13
- err := Listen (nil )
13
+ err := Listen (Options {} )
14
14
if err != nil {
15
15
t .Fatal (err )
16
16
}
17
17
Close ()
18
18
}
19
19
20
20
func TestAgentClose (t * testing.T ) {
21
- err := Listen (nil )
21
+ err := Listen (Options {} )
22
22
if err != nil {
23
23
t .Fatal (err )
24
24
}
@@ -33,7 +33,7 @@ func TestAgentClose(t *testing.T) {
33
33
}
34
34
35
35
func TestAgentListenMultipleClose (t * testing.T ) {
36
- err := Listen (nil )
36
+ err := Listen (Options {} )
37
37
if err != nil {
38
38
t .Fatal (err )
39
39
}
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ import (
12
12
)
13
13
14
14
func main () {
15
- if err := agent .Listen (nil ); err != nil {
15
+ if err := agent .Listen (agent.Options {
16
+ ShutdownCleanup : true , // automatically closes on os.Interrupt
17
+ }); err != nil {
16
18
log .Fatal (err )
17
19
}
18
20
time .Sleep (time .Hour )
You can’t perform that action at this time.
0 commit comments