Alternative Go Playground frontend written in Go

1,003 views
Skip to first unread message

Igor Afanasyev

unread,
Jun 5, 2017, 1:39:03 AM6/5/17
to golang-dev
Hi golang-dev,

As per play.golang.org usage terms, I'm writing here to inform that I'm using its backend for another project: Go Play Space. It is an experimental alternative Go Playground frontend that is built in Go itself (using GopherJS), a Go→JavaScript transpiler, and Vecty, a React-like frontend library for GopherJS).

Go Play Space uses a unique User-Agent header, and I hope it will be of benefit to the Go community.
Now to a more informal part: the idea behind this small project was not only to experiment with GopherJS/Vecty, but also to imagine how Go Playground could be improved and better integrated with language/package documentation.

What Go Play Space has is:
  1. Smart Golang help lookup: one can double-click (select) some keyword, function name or operator, and see the relevant help topic on a right pane
  2. Syntax highlighting
  3. Live syntax error checking and reporting
  4. One can not only share the snippets, but also highlight the lines of code (as on Github) and share snippets along with highlighted lines.
  5. Some UI themes to choose from (for better readability) and support for Fira Code (monospaced font with ligatures)
  6. Keyboard shortcuts for formatting/running the code and to toggle line selection.
I hope it will serve as a concept for future official Go Playground improvements — I know there are some plans to do so.


--Igor

Brad Fitzpatrick

unread,
Jun 5, 2017, 12:26:05 PM6/5/17
to Igor Afanasyev, golang-dev
Neat!


--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Griesemer

unread,
Jun 5, 2017, 12:33:20 PM6/5/17
to Igor Afanasyev, golang-dev
very nice, indeed!
- gri

On Sun, Jun 4, 2017 at 10:20 PM, Igor Afanasyev <igor.af...@gmail.com> wrote:

--

Aram Hăvărneanu

unread,
Jun 5, 2017, 1:07:38 PM6/5/17
to Robert Griesemer, Igor Afanasyev, golang-dev
Unfortunately you can't turn off the syntax highlighting.

--
Aram Hăvărneanu

Tyler Compton

unread,
Jun 5, 2017, 2:02:40 PM6/5/17
to Aram Hăvărneanu, Robert Griesemer, Igor Afanasyev, golang-dev
This looks like a great tool! For how long can we expect our snippets to be saved? If you're hosting this server out of pocket, perhaps it would be best if we edit in goplay.space and save in play.golang.org.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Tyler Compton
Software Engineering

Igor Afanasyev

unread,
Jun 5, 2017, 2:15:36 PM6/5/17
to Tyler Compton, golang-dev
Hi Tyler,

This looks like a great tool! For how long can we expect our snippets to be saved? If you're hosting this server out of pocket, perhaps it would be best if we edit in goplay.space and save in play.golang.org.

This is exactly how it is working now — it saves snippets to and retrieves them from play.golang.org. Snippet IDs are also taken from golang.org servers, so https://goplay.space/#irjmuWTag1 == https://play.golang.org/p/irjmuWTag1


--Igor

Igor Afanasyev

unread,
Jun 5, 2017, 2:18:31 PM6/5/17
to Aram Hăvărneanu, golang-dev
Hi Aram,

Unfortunately you can't turn off the syntax highlighting.

I was thinking about adding such an option, thanks!


--Igor

Igor Afanasyev

unread,
Jun 6, 2017, 1:00:44 AM6/6/17
to golang-dev
A quick follow-up: by popular demand, I added an ability to choose tab width (which now defaults to 4 symbols), and syntax highlighting can be turned off as well. Enjoy!


--Igor

Matt Harden

unread,
Jun 6, 2017, 10:48:03 AM6/6/17
to Igor Afanasyev, golang-dev
Sweet. Since Fira Code can't be installed on a chromebook, it would be great if you loaded it via web fonts. Example: https://github.com/tonsky/FiraCode/blob/master/distr/specimen.html.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.

Igor Afanasyev

unread,
Jun 6, 2017, 7:51:41 PM6/6/17
to Matt Harden, golang-dev
Hi Matt,

Sweet. Since Fira Code can't be installed on a chromebook, it would be great if you loaded it via web fonts.

Done. Check the updated Settings pane. Also i added an ability to select a lighter font weight.
 

--Igor

roger peppe

unread,
Jun 14, 2017, 3:54:03 AM6/14/17
to Igor Afanasyev, golang-dev
This looks cool, thanks (and thanks for adding the capability to turn
off syntax highlighting).

While we're on the subject, one feature I'd love to see in a playground
is the ability to run non-stdlib code. ISTM that it would be possible to make
imports work from any package that you can see under godoc.org.
There are a few hurdles (e.g. compile time, dependency locking), but
it would be really great to be able to easily demo third party package
functionality in the playground.

Igor Afanasyev

unread,
Jun 19, 2017, 2:18:16 PM6/19/17
to roger peppe, Brad Fitzpatrick, golang-dev
Hi Roger,

I guess this is more of a question to the official Go Playground maintainers. I too wish there was a way to run code in Playground against third-party libraries, and I think it would be very beneficial to the community.

I started to think of how this could be implemented, and came up with the idea I'll describe below.

Some assumptions first:
  1. I assume that running some third-party library code is not a problem from a security standpoint, as this untrusted code doesn't differ from an untrusted code of the main program the Playground is running, so it's more about the implementation details.
  2. I also think that an ability to run against different versions of the third-party libraries is important (not to break old code; to be able to demo the new and old library APIs, etc.).
Now that Go supports /vendor folder, the Playground could leverage that vendoring ability, so this is how this could be implemented:
  1. Third-party packages (one or more) are zipped in a package bundle. The zip file should have the following structure:
    github.com/author1/package1
    github.com/author2/package2
    ...
    local/package3
    ...
  2. User goes to Go Playground, presses the "Upload vendor bundle" button and uploads their zip file. A standard 64KB [or other reasonable] upload file size limit may be applied here.
  3. Go Playground processes the zip file, calculates its unique hash the same way it does it for the main Go source, stores it the same way and redirects the user to e.g. play.golang.org/v/BuNdl3HasH (where BuNdl3HasH is that unique hash). This URL becomes the base URL for all playground code that runs against that vendor bundle. Package authors can share this URL on their project pages, essentially offering customized Go Playgrounds for users who want to experiment with their package.
  4. Now the user goes to play.golang.org/v/BuNdl3HasH and writes some code that can reference any non-standard package provided in that bundle.
  5. When the submitted code is about to be compiled, the zip bundle is automatically unzipped into the /vendor subfolder before the compilation.
  6. If the user wants to share the code based on the bundle and presses the "Share" button, the URL becomes: play.golang.org/v/BuNdl3HasH/p/C0dEhaSH
  7. Playground should probably have some means of showing the contents of the vendor bundle (either as zip directory/file structure, or as a list of exposed package names).

@Brad Fitzpatrick: I could experiment with implementing this on top of the code published at https://github.com/golang/playground/ if maintainers think it's the right way to approach this. This Github repo is a mirror and doesn't have Issues tab exposed there, so I'm not sure what's the right way to make feature requests and implementation proposals for the playground before diving into the actual implementation. What would you suggest?


Best regards,
Igor Afanasyev


Russ Cox

unread,
Jun 19, 2017, 2:24:21 PM6/19/17
to Igor Afanasyev, roger peppe, Brad Fitzpatrick, golang-dev
What about using GopherJS to run the snippets? Then there's no need for the playground back ends at all. Is GopherJS good enough for that?

Igor Afanasyev

unread,
Jun 19, 2017, 3:24:00 PM6/19/17
to Russ Cox, roger peppe, Brad Fitzpatrick, golang-dev
GopherJS has its limitations, but most importantly, one can't compile arbitrary packages at run time (in the client). This still requires a backend. And backend is also needed to store shared code snippets.


Best regards,
Igor Afanasyev

Russ Cox

unread,
Jun 19, 2017, 5:04:22 PM6/19/17
to Igor Afanasyev, roger peppe, Brad Fitzpatrick, golang-dev
Right, the back end is definitely needed for holding snippets. For execution, I was kind of hoping that GopherJS had been compiled using itself into Javascript so that you could take the Go source, feed it through GopherJS (running in the browser), and then eval the resulting JS. Maybe GopherJS isn't there yet though.

Russ

Igor Afanasyev

unread,
Jun 19, 2017, 5:57:32 PM6/19/17
to Russ Cox, roger peppe, Brad Fitzpatrick, golang-dev
GopherJS actually does just that in their playground (but not for third-party packages).


Best regards,
Igor Afanasyev

Richard Musiol

unread,
Jun 19, 2017, 7:43:56 PM6/19/17
to golang-dev, r...@golang.org, rogp...@gmail.com, brad...@golang.org
Author of GopherJS here.

Yes, GopherJS can compile itself. This was one of the first milestones and, as Igor already said, the GopherJS playground is based on that. The playground only compiles a single file, but that is only because there is no need for more in the playground. In theory you can compile whole third-party packages in-memory. The compiler core is not dependent on a disk.

Best,
Richard


Best regards,
Igor Afanasyev


Best regards,
Igor Afanasyev



Best regards,
Igor Afanasyev



> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages