8000 chore: completely remove sharing · soulteary/golang-playground@7981e56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7981e56

Browse files
committed
chore: completely remove sharing
1 parent e73dacb commit 7981e56

File tree

7 files changed

+2
-202
lines changed

7 files changed

+2
-202
lines changed

src/edit.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
package main
66

77
import (
8-
"fmt"
98
"html/template"
109
"net/http"
1110
"runtime"
1211
"strings"
13-
14-
"cloud.google.com/go/datastore"
1512
)
1613

1714
const hostname = "play.golang.org"
@@ -20,7 +17,6 @@ var editTemplate = template.Must(template.ParseFiles("edit.html"))
2017

2118
type editData struct {
2219
Snippet *snippet
23-
Share bool
2420
Analytics bool
2521
GoVersion string
2622
Gotip bool
@@ -40,44 +36,7 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) {
4036
return
4137
}
4238

43-
// Serve 404 for /foo.
44-
if r.URL.Path != "/" && !strings.HasPrefix(r.URL.Path, "/p/") {
45-
http.NotFound(w, r)
46-
return
47-
}
48-
4939
snip := &snippet{Body: []byte(s.examples.hello())}
50-
if strings.HasPrefix(r.URL.Path, "/p/") {
51-
if !allowShare(r) {
52-
w.WriteHeader(http.StatusUnavailableForLegalReasons)
53-
w.Write([]byte(`<h1>Unavailable For Legal Reasons</h1><p>Viewing and/or sharing code snippets is not available in your country for legal reasons. This message might also appear if your country is misdetected. If you believe this is an error, please <a href="https://golang.org/issue">file an issue</a>.</p>`))
54-
return
55-
}
56-
id := r.URL.Path[3:]
57-
serveText := false
58-
if strings.HasSuffix(id, ".go") {
59-
id = id[:len(id)-3]
60-
serveText = true
61-
}
62-
63-
if err := s.db.GetSnippet(r.Context(), id, snip); err != nil {
64-
if err != datastore.ErrNoSuchEntity {
65-
s.log.Errorf("loading Snippet: %v", err)
66-
}
67-
http.Error(w, "Snippet not found", http.StatusNotFound)
68-
return
69-
}
70-
if serveText {
71-
if r.FormValue("download") == "true" {
72-
w.Header().Set(
73-
"Content-Disposition", fmt.Sprintf(`attachment; filename="%s.go"`, id),
74-
)
75-
}
76-
w.Header().Set("Content-type", "text/plain; charset=utf-8")
77-
w.Write(snip.Body)
78-
return
79-
}
80-
}
8140

8241
if r.Host == hostname {
8342
// The main playground is now on go.dev/play.
@@ -88,7 +47,6 @@ func (s *server) handleEdit(w http.ResponseWriter, r *http.Request) {
8847
w.Header().Set("Content-Type", "text/html; charset=utf-8")
8948
data := &editData{
9049
Snippet: snip,
91-
Share: allowShare(r),
9250
GoVersion: runtime.Version(),
9351
Gotip: s.gotip,
9452
Examples: s.examples.examples,

src/edit.html

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,11 @@
2525
'runEl': '#run, #embedRun',
2626
'fmtEl': '#fmt',
2727
'fmtImportEl': '#imports',
28-
{{if $.Share}}
29-
'shareEl': '#share',
30-
'shareURLEl': '#shareURL',
31-
{{end}}
3228
'enableHistory': true,
3329
'enableShortcuts': true,
3430
'enableVet': true,
3531
'toysEl': '.js-playgroundToysEl'
3632
});
37-
playgroundEmbed({
38-
'codeEl': '#code',
39-
{{if $.Share}}
40-
'shareEl': '#share',
41-
{{end}}
42-
'embedEl': '#embed',
43-
'embedLabelEl': '#embedLabel',
44-
'embedHTMLEl': '#shareURL'
45-
});
4633
$('#code').linedtextarea();
4734
// Avoid line wrapping.
4835
$('#code').attr('wrap', 'off');
@@ -68,19 +55,13 @@
6855
createCookie('playgroundImports', $(this).is(':checked') ? 'true' : '');
6956
});
7057
{{if .Analytics}}
71-
// Fire Google Analytics events for Run/Share button clicks.
58+
// Fire Google Analytics events for Run button clicks.
7259
$('#run').click(function() {
7360
gtag('event', 'click', {
7461
event_category: 'playground',
7562
event_label: 'run-button',
7663
});
7764
});
78-
$('#share').click(function() {
79-
gtag('event', 'click', {
80-
event_category: 'playground',
81-
event_label: 'share-button',
82-
});
83-
});
8465
{{end}}
8566
});
8667

@@ -112,14 +93,6 @@
11293
Imports
11394
</label>
11495
</div>
115-
{{if $.Share}}
116-
<input type="button" value="Share" id="share">
117-
<input type="text" id="shareURL">
118-
<label id="embedLabel">
119-
<input type="checkbox" id="embed">
120-
embed
121-
</label>
122-
{{end}}
12396
<select class="js-playgroundToysEl">
12497
{{range .Examples}}
12598
<option value="{{.Path}}">{{.Title}}</option>

src/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func (s *server) init() {
5454
s.mux.HandleFunc("/version", s.handleVersion)
5555
s.mux.HandleFunc("/vet", s.commandHandler("vet", vetCheck))
5656
s.mux.HandleFunc("/compile", s.commandHandler("prog", compileAndRun))
57-
s.mux.HandleFunc("/share", s.handleShare)
5857
s.mux.HandleFunc("/playground.js", s.handlePlaygroundJS)
5958
s.mux.HandleFunc("/favicon.ico", handleFavicon)
6059
s.mux.HandleFunc("/_ah/health", s.handleHealthCheck)

src/server_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func TestServer(t *testing.T) {
114114
t.Fatalf("newServer(testingOptions(t)): %v", err)
115115
}
116116

117-
const shareURL = "https://play.golang.org/share"
118117
testCases := []struct {
119118
desc string
120119
method string
@@ -123,12 +122,6 @@ func TestServer(t *testing.T) {
123122
reqBody []byte
124123
respBody []byte
125124
}{
126-
// Share tests.
127-
{"OPTIONS no-op", http.MethodOptions, shareURL, http.StatusOK, nil, nil},
128-
{"Non-POST request", http.MethodGet, shareURL, http.StatusMethodNotAllowed, nil, nil},
129-
{"Standard flow", http.MethodPost, shareURL, http.StatusOK, []byte("Snippy McSnipface"), []byte("N_M_YelfGeR")},
130-
{"Snippet too large", http.MethodPost, shareURL, http.StatusRequestEntityTooLarge, make([]byte, maxSnippetSize+1), nil},
131-
132125
// Examples tests.
133126
{"Hello example", http.MethodGet, "https://play.golang.org/doc/play/hello.txt", http.StatusOK, nil, []byte("Hello")},
134127
{"HTTP example", http.MethodGet, "https://play.golang.org/doc/play/http.txt", http.StatusOK, nil, []byte("net/http")},

src/share.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
package main
66

77
import (
8-
"bytes"
98
"crypto/sha256"
109
"encoding/base64"
11-
"fmt"
1210
"io"
13-
"net/http"
1411
)
1512

1613
const (
@@ -41,50 +38,3 @@ func (s *snippet) ID() string {
4138
}
4239
return string(b)[:hashLen]
4340
}
44-
45-
func (s *server) handleShare(w http.ResponseWriter, r *http.Request) {
46-
w.Header().Set("Access-Control-Allow-Origin", "*")
47-
if r.Method == "OPTIONS" {
48-
// This is likely a pre-flight CORS request.
49-
return
50-
}
51-
if r.Method != "POST" {
52-
http.Error(w, "Requires POST", http.StatusMethodNotAllowed)
53-
return
54-
}
55-
if !allowShare(r) {
56-
http.Error(w, "Either this isn't available in your country due to legal reasons, or our IP geolocation is wrong.",
57-
http.StatusUnavailableForLegalReasons)
58-
return
59-
}
60-
61-
var body bytes.Buffer
62-
_, err := io.Copy(&body, io.LimitReader(r.Body, maxSnippetSize+1))
63-
r.Body.Close()
64-
if err != nil {
65-
s.log.Errorf("reading Body: %v", err)
66-
http.Error(w, "Server Error", http.StatusInternalServerError)
67-
return
68-
}
69-
if body.Len() > maxSnippetSize {
70-
http.Error(w, "Snippet is too large", http.StatusRequestEntityTooLarge)
71-
return
72-
}
73-
74-
snip := &snippet{Body: body.Bytes()}
75-
id := snip.ID()
76-
if err := s.db.PutSnippet(r.Context(), id, snip); err != nil {
77-
s.log.Errorf("putting Snippet: %v", err)
78-
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
79-
return
80-
}
81-
82-
fmt.Fprint(w, id)
83-
}
84-
85-
func allowShare(r *http.Request) bool {
86-
if r.Header.Get("X-AppEngine-Country") == "CN" {
87-
return false
88-
}
89-
return true
90-
}

src/static/playground-embed.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/static/style.css

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ input[type=button],
135135
align-items: center;
136136
line-height: 1.2;
137137
}
138-
#shareURL {
139-
width: 280px;
140-
font-size: 16px;
141-
border: 1px solid #ccc;
142-
background: #eee;
143-
color: black;
144-
}
138+
145139
#embedLabel {
146140
font-family: sans-serif;
147141
padding-top: 5px;

0 commit comments

Comments
 (0)
0