Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
d574d03a
Commit
d574d03a
authored
Nov 12, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Cleanup Requests after command execution returns
parent
f724440c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
command.go
command.go
+8
-0
request.go
request.go
+16
-0
No files found.
command.go
View file @
d574d03a
...
...
@@ -97,6 +97,14 @@ func (c *Command) Call(req Request) Response {
return
res
}
// clean up the request (close the readers, e.g. fileargs)
// NOTE: this means commands can't expect to keep reading after cmd.Run returns (in a goroutine)
err
=
req
.
Cleanup
()
if
err
!=
nil
{
res
.
SetError
(
err
,
ErrNormal
)
return
res
}
res
.
SetOutput
(
output
)
return
res
}
...
...
request.go
View file @
d574d03a
...
...
@@ -3,6 +3,7 @@ package commands
import
(
"errors"
"fmt"
"io"
"reflect"
"strconv"
...
...
@@ -28,6 +29,7 @@ type Request interface {
Context
()
*
Context
SetContext
(
Context
)
Command
()
*
Command
Cleanup
()
error
ConvertOptions
()
error
}
...
...
@@ -119,6 +121,20 @@ func (r *request) Command() *Command {
return
r
.
cmd
}
func
(
r
*
request
)
Cleanup
()
error
{
for
_
,
arg
:=
range
r
.
arguments
{
closer
,
ok
:=
arg
.
(
io
.
Closer
)
if
ok
{
err
:=
closer
.
Close
()
if
err
!=
nil
{
return
err
}
}
}
return
nil
}
type
converter
func
(
string
)
(
interface
{},
error
)
var
converters
=
map
[
reflect
.
Kind
]
converter
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment