Skip to content

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

Merged
merged 12 commits into from
Jan 7, 2015
Merged

Initial implementation. #1

merged 12 commits into from
Jan 7, 2015

Conversation

dmitshur
Copy link
Member

@dmitshur dmitshur commented Jan 6, 2015

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 of pHandler can probably be made better. Like, determine the source of snippet (an io.Reader), and then have one place that does io.Copy(w, snippet).

Also, maybe better docs.

That's all I can think of.

@dmitshur
Copy link
Member Author

dmitshur commented Jan 6, 2015

Actually,

Newly shared snippets are stored locally in the specified folder and take precedence.

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)
Copy link
Member

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

Copy link
Member Author

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.

@dmitshur
Copy link
Member Author

dmitshur commented Jan 6, 2015

@dominikh, I've addressed all your feedback, PTAL.

I've also addressed my own feedback.

return
}

body, err := ioutil.ReadAll(req.Body)
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

@dominikh
Copy link
Member

dominikh commented Jan 6, 2015

LGTM


err = http.ListenAndServe(*httpFlag, nil)
if err != nil {
log.Println("ListenAndServe:", err)
Copy link
Member Author

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.

dmitshur added a commit that referenced this pull request Jan 7, 2015
@dmitshur dmitshur merged commit 0e0e3e6 into master Jan 7, 2015
@dmitshur dmitshur deleted the initial-implementation branch January 7, 2015 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants