-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serve easily dynamic files with DataFromReader
context method
#1304
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1304 +/- ##
==========================================
+ Coverage 98.19% 98.21% +0.01%
==========================================
Files 34 35 +1
Lines 1826 1846 +20
==========================================
+ Hits 1793 1813 +20
Misses 26 26
Partials 7 7
Continue to review full report at Codecov.
|
DataFromReader
context method
@thinkerou Could you also help to review this PR? |
@appleboy @jclebreton Except for comments, LGTM to me. Thanks! |
@@ -834,6 +834,32 @@ func main() { | |||
} | |||
``` | |||
|
|||
### Serving data from reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add content link in README, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @thinkerou I'm not sure to understand the target of the asked link. This page ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks
render/reader.go
Outdated
// Render (Reader) writes data with custom ContentType and headers. | ||
func (r Reader) Render(w http.ResponseWriter) (err error) { | ||
r.WriteContentType(w) | ||
r.Headers["Content-Length"] = fmt.Sprintf("%d", r.ContentLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use strconv.Itoa(r.ContentLength)
? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. It's better to use strconv
library but to convert a int64 variable to a string strconv.FormatInt(r.ContentLength, 10)
works better ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
68b44cf
to
157ffdb
Compare
render/render_test.go
Outdated
"testing" | ||
|
||
"strings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the extra empty line between internal package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ;-)
157ffdb
to
9dca295
Compare
need @thinkerou approvl. |
LGTM |
func (r Reader) writeHeaders(w http.ResponseWriter, headers map[string]string) { | ||
header := w.Header() | ||
for k, v := range headers { | ||
if val := header[k]; len(val) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I prefer to using val == ""
for judging empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jclebreton Please update and I will merge this.
Thanks for review and merge ;-) |
This pull request adds a new method called
DataFromReader
to provides an easy way to serve dynamic files.