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
Commits
f76048f7
Commit
f76048f7
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Unexported Handler fields and created constructor
parent
4552fce5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
commands/http/handler.go
commands/http/handler.go
+9
-5
No files found.
commands/http/handler.go
View file @
f76048f7
...
...
@@ -9,8 +9,8 @@ import (
)
type
Handler
struct
{
C
tx
cmds
.
Context
R
oot
*
cmds
.
Command
c
tx
cmds
.
Context
r
oot
*
cmds
.
Command
}
var
ErrNotFound
=
errors
.
New
(
"404 page not found"
)
...
...
@@ -21,8 +21,12 @@ var mimeTypes = map[string]string{
cmds
.
Text
:
"text/plain"
,
}
func
NewHandler
(
ctx
cmds
.
Context
,
root
*
cmds
.
Command
)
*
Handler
{
return
&
Handler
{
ctx
,
root
}
}
func
(
i
Handler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
req
,
err
:=
Parse
(
r
,
i
.
R
oot
)
req
,
err
:=
Parse
(
r
,
i
.
r
oot
)
if
err
!=
nil
{
if
err
==
ErrNotFound
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
...
...
@@ -32,10 +36,10 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
req
.
SetContext
(
i
.
C
tx
)
req
.
SetContext
(
i
.
c
tx
)
// call the command
res
:=
i
.
R
oot
.
Call
(
req
)
res
:=
i
.
r
oot
.
Call
(
req
)
// set the Content-Type based on res output
if
_
,
ok
:=
res
.
Output
()
.
(
io
.
Reader
);
ok
{
...
...
This diff is collapsed.
Click to expand it.
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