blob: 277a6eee5425b563e822a4b2fd251c363daeabe0 [file] [log] [blame]
<!doctype html>
<title>The Go Playground</title>
<link rel="stylesheet" href="/static/style.css">
<script src="//"></script>
<script src="/static/jquery-linedtextarea.js"></script>
<script src="/playground.js"></script>
<script src="/static/playground-embed.js"></script>
$(document).ready(function() {
'codeEl': '#code',
'outputEl': '#output',
'runEl': '#run',
'fmtEl': '#fmt',
'fmtImportEl': '#imports',
'shareEl': '#share',
'shareURLEl': '#shareURL',
'enableHistory': true
'codeEl': '#code',
'shareEl': '#share',
'embedEl': '#embed',
'embedLabelEl': '#embedLabel',
'embedHTMLEl': '#shareURL'
// Avoid line wrapping.
$('#code').attr('wrap', 'off');
var about = $('#about'); {
if ($('a')) {
$('#aboutButton').click(function() {
if (':visible')) {
// Preserve "Imports" checkbox value between sessions.
if (readCookie('playgroundImports') == 'true')
$('#imports').change(function() {
createCookie('playgroundImports', $(this).is(':checked') ? 'true' : '');
// Fire Google Analytics events for Run/Share button clicks.
if (window.trackEvent) {
$('#run').click(function() {
window.trackEvent('playground', 'click', 'run-button');
$('#share').click(function() {
window.trackEvent('playground', 'click', 'share-button');
function createCookie(name, value) {
document.cookie = name+"="+value+"; path=/";
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
return null;
<body itemscope itemtype="">
<div id="banner">
<div id="head" itemprop="name">The Go Playground</div>
<div id="controls">
<input type="button" value="Run" id="run">
<input type="button" value="Format" id="fmt">
<div id="importsBox">
<label title="Rewrite imports on Format">
<input type="checkbox" id="imports">
<input type="button" value="Share" id="share">
<input type="text" id="shareURL">
<label id="embedLabel">
<input type="checkbox" id="embed">
<div id="aboutControls">
<input type="button" value="About" id="aboutButton">
<div id="wrap">
<textarea itemprop="description" id="code" name="code" autocorrect="off" autocomplete="off" autocapitalize="off" spellcheck="false">{{printf "%s" .Snippet.Body}}</textarea>
<div id="output"></div>
<img itemprop="image" src="/static/gopher.png" style="display:none">
<div id="about">
<p><b>About the Playground</b></p>
The Go Playground is a web service that runs on
<a href="//"></a>'s servers.
The service receives a Go program, compiles, links, and
runs the program inside a sandbox, then returns the output.
There are limitations to the programs that can be run in the playground:
The playground can use most of the standard library, with some exceptions.
The only communication a playground program has to the outside world
is by writing to standard output and standard error.
In the playground the time begins at 2009-11-10 23:00:00 UTC
(determining the significance of this date is an exercise for the reader).
This makes it easier to cache programs by giving them deterministic output.
There are also limits on execution time and on CPU and memory usage.
The article "<a href="//" target="_blank">Inside
the Go Playground</a>" describes how the playground is implemented.
The playground uses the latest stable release of Go.<br>
To find the precise version, run <a href="/p/1VcPUlPk_3">this program</a>.
The playground service is used by more than just the official Go project
(<a href="//">Go by Example</a> is one other instance)
and we are happy for you to use it on your own site.
All we ask is that you <a href="">contact us first</a>,
use a unique user agent in your requests (so we can identify you),
and that your service is of benefit to the Go community.