-
Notifications
You must be signed in to change notification settings - Fork 11
Playground: Gist support #6
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
Comments
GitHub API allows CORS, so fetching the gist contents from a gist id can be done in the frontend as easily as this: gistUrl := "https://api.github.com/gists/" + gistId
data, err := xhr.Send("GET", gistUrl, nil)
if err != nil {
return err
}
var gistJson struct {
Files map[string]struct{ Content string }
}
err = json.Unmarshal([]byte(data), &gistJson)
if err != nil {
return err
}
for filename, file := range gistJson.Files {
// Use file.Content
} |
That is excellent. Cheers! |
Relevant: gopherjs/gopherjs#95 |
Alright, I have gist support working, but I am trying to come up with a strategy.
My instinct says 5. We don't want to support multiple files in the editor, and multiple go files in a gist might not even be related or in the same package. Thoughts? |
I'd keep it simple and allow exactly one file in the gist and load that file. I wouldn't necessarily check that it's a Go file, as people or tools might be lazy and push unnamed and untyped files as gists. |
That is a good point. If the user wants to load up some Scala code and try to compile it, it isn't going to hurt anything anyway. |
I think it'd be helpful to take a step back and think about the problem as a whole. Ideally, what we want is something like what play.golang.org offers, the ability to take current content (something the person likely iterated on after running it multiple times within the playground) and save/share it, then reload it from that url. The ability to load gists is secondary to that, because from what I can tell, saving gists is far from a quick experience (you have to select all text in the playground, copy it, open a new tab, go to gists.github.com, login to github if you're not, paste, press a button). So it's unlikely there will be interesting things to load from gists. Unless we leverage the GitHub API to save anonymous gists from the GopherJS playground in one button press. At that point, it simply becomes the storage we use for programs. I guess what I'm suggesting is that it's important to consider both the saving and loading experience together. That said, I agree with the above, it's probably best to keep it as simple as possible and allow one file. Also, if we implement saving to gists, then you know what to expect when loading. |
If play.golang.org has any sort of API that would allow us to fetch/save contents, I would argue that is the best storage to (re)use, since then a But I'm not sure we can do that. |
I inspected play.golang.org and it seems like saving is just a simple POST request:
For loading we would need to extract the content of the textarea returned by
It's possible to do that, but I feel like we should ask the Go team first, maybe at the golang-dev mailing list. |
I was originally coming at it only from the idea of loading a gist, not sharing from the playground. I absolutely agree that using the Go playground like that would be super cool. Would you like to ask about that Richard? It might look better coming from the creator of GopherJS. Anonymous gists seems like it would be wasteful, since it would be impossible to associate the code in the editor with an gist id. No matter how many times someone shares, for example, the default code, a new gist would be created. Also, there is a 60 anon gists per hour limit I believe. |
Append
|
Nice! |
I assume they will say it is ok. Other tools, like editor plugins, use the service like that already. |
Okay, then let's add it to our playground. It will be great! |
The rule generally is that you ask/let the Go team know that you intend to use the playground in your service. Admittedly, they primarily care due to code compilation, not the pastebin aspect, but at least letting them know sounds like a nice thing to do.
|
I guess we might need a |
Sure, give me a few minutes. I am adding and testing it right now. |
Indeed, I am getting the Access-Control-Allow-Origin error. Looks like we will have to ask for that if this is going to work. |
For it to work completely from the frontend. CORS isn't a concern if done in the backend. Of course, we should absolutely ask for permission/let them know regardless of whether there are technical adjustments to be made or not, as @dominikh pointed out in #6 (comment). |
I really can't anticipate how they will respond. Seems like a slippery slope if they open up for us. It would also make it hard to test locally. It would be awesome if they just had a simple JSON api. :) For now I will keep the Gist support, and we can revisit this when we know more. |
We'll never know if we don't ask. Given that "and that your service is of benefit to the Go community" IMO is satisfied, I think our chances are pretty good. @neelance, are you going to post on the mailing list (probably the Edit: We only want to use the pastebin aspect of the API, which is less computationally expensive than using the compile and execute Go code part... I think that should hopefully improve our chances. |
Yes, please go ahead. |
I've done so here. |
Well, we have partial success! https://groups.google.com/d/msg/golang-dev/zSK8WhhiYDE/tub0B5svp9wJ @adg said we're okay to load snippets from Go playground, but we shouldn't store new ones there. I'm guessing they're not yet very familiar with GopherJS and the kind of Go programs/snippets it's likely to compile, so they don't want those unknown programs polluting the namespace, which is fair (and I'm sure the decision can be revisited in the future once the unknowns become more known). It's possible many will use the Since we will definitely need a backend to store the snippets, there's not much point in asking for CORS for loading, as the backend can simply forward that along. It seems that we'll need a simple backend for storing GopherJS playground Go code snippets. It doesn't seem very hard to create. I can volunteer to do it. The main requirements would be:
Am I missing anything? |
Separately, we need to decide on a frontend URL scheme. How about: http://play.golang.org/p/D9L6MbPfE4 (Since the playground is served as part of a static website, as far as I know, it has to be a query parameter. Correct?) |
Two alternative schemes: http://gopherjs.org/play/?p=D9L6MbPfE4 Any preference? /cc @ajhager |
I'm working on this now (@ajhager, feel free to assign this issue to me; I can't because I don't have push rights for this repo), quick question for @ajhager or @neelance: Is it okay if I use |
Ok, I have this working and pretty close to done. The backend component is almost done, just needs final review. The frontend components works, but needs to be cleaned up and use AngularJS better. The PR for the backend component ready for final review, see gopherjs/snippet-store#1. The PR for the frontend change is very rough, and has lots of TODOs and code cleanup remaining, but just to get the process started, see PR #11. I've setup a temporary copy of the playground where you can test out the snippet loading/saving, etc. The compiling doesn't work because I didn't update the compiler files but my http://dmitri.shuralyov.com/temp/playground/index.html There are some minor usability bugs to iron out with the frontend (see PR for details), but it should mostly work. Let me know what you think! |
@shurcooL I'll give you push rights to this repo. |
I think it should be okay. |
This is done and deployed. I've immediately found a minor issue #14, and fixed it in #15. http://gopherjs.org/play/#/Myqj0bQVev is the first official GopherJS Playground snippet. Feel free to share your snippets, and please report any issues if you find any! We want the experience to be nothing short of delightful. |
We do not support sharing directly from the playground, since it is all client side. Adding the ability to load Github gists or Golang playground code by id should help fill in that gap.
We also might be able to add a route in angularjs like /playground/[gist-id] that automatically loads the code from the gist with that id.
The text was updated successfully, but these errors were encountered: