Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
b87e6ccb
Commit
b87e6ccb
authored
Mar 28, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored markdown middleware to return errors
parent
22707edc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
middleware/markdown/markdown.go
middleware/markdown/markdown.go
+10
-6
No files found.
middleware/markdown/markdown.go
View file @
b87e6ccb
...
...
@@ -6,6 +6,7 @@ import (
"bytes"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
...
...
@@ -20,7 +21,7 @@ type Markdown struct {
Root
string
// Next HTTP handler in the chain
Next
http
.
HandlerFunc
Next
middleware
.
HandlerFunc
// The list of markdown configurations
Configs
[]
MarkdownConfig
...
...
@@ -57,14 +58,14 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
Configs
:
mdconfigs
,
}
return
func
(
next
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
next
middleware
.
HandlerFunc
)
middleware
.
HandlerFunc
{
md
.
Next
=
next
return
md
.
ServeHTTP
},
nil
}
// ServeHTTP implements the http.Handler interface.
func
(
md
Markdown
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
md
Markdown
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
for
_
,
m
:=
range
md
.
Configs
{
if
!
middleware
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
m
.
PathScope
)
{
continue
...
...
@@ -76,7 +77,10 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body
,
err
:=
ioutil
.
ReadFile
(
fpath
)
if
err
!=
nil
{
panic
(
err
)
// TODO
if
os
.
IsPermission
(
err
)
{
return
http
.
StatusForbidden
,
err
}
return
http
.
StatusNotFound
,
nil
}
content
:=
blackfriday
.
Markdown
(
body
,
m
.
Renderer
,
0
)
...
...
@@ -112,13 +116,13 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w
.
Write
([]
byte
(
html
))
return
return
http
.
StatusOK
,
nil
}
}
}
// Didn't qualify to serve as markdown; pass-thru
md
.
Next
(
w
,
r
)
return
md
.
Next
(
w
,
r
)
}
// parse creates new instances of Markdown middleware.
...
...
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