-
Notifications
You must be signed in to change notification settings - Fork 0
Initial implementation. #1
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
Conversation
Actually,
That part is not implemented yet. Currently the Go Playground snippets take precedence. |
Since they're quite long, I am hoping this is an improvement to readability. Note that snippet serving precedence is still TODO.
|
||
id := req.URL.Path[len("/p/"):] | ||
|
||
req2, err := http.NewRequest("GET", "http://play.golang.org/p/"+id+".go", nil) |
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.
Move the whole "fetch snippet from play.golang.org" functionality into its own function
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 idea, I'll try that.
Split into multiple logical files.
@dominikh, I've addressed all your feedback, PTAL. I've also addressed my own feedback. |
return | ||
} | ||
|
||
body, err := ioutil.ReadAll(req.Body) |
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.
Wrap the body in an http.MaxBytesReader and set a sane max size
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.
Nice, thanks for the tip! Can I just use it like ioutil.ReadAll(http.MaxBytesReader(w, req.Body, n))
?
What would be a good limit? 1 MB perhaps?
If space starts to become an issue, we can start using compression.
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.
Yes, you can.
1 MB sounds like a good enough limit to keep attacks at bay while allowing any reasonable snippet.
LGTM |
|
||
err = http.ListenAndServe(*httpFlag, nil) | ||
if err != nil { | ||
log.Println("ListenAndServe:", err) |
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.
Should use log.Fatalln
here.
Improve docs style. Use fatal on ListenAndServe error.
Needed for gopherjs/gopherjs.github.io#6.
Review welcome.
I think the code is pretty clean, the only comments I have is that the logic flow of
switch resp.StatusCode {
at the bottom ofpHandler
can probably be made better. Like, determine the source of snippet (anio.Reader
), and then have one place that doesio.Copy(w, snippet)
.Also, maybe better docs.
That's all I can think of.