Skip to content

Commit 9af0f0e

Browse files
authored
Merge pull request #39 from x1unix/dev
1.6.0 - Final
2 parents 577ab7b + 955d435 commit 9af0f0e

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

build/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ WORKDIR /opt/playground
2424
ENV GOROOT /usr/local/go
2525
ENV APP_CLEAN_INTERVAL=10m
2626
ENV APP_DEBUG=false
27+
ENV APP_PLAYGROUND_URL=https://play.golang.org
2728
COPY data ./data
2829
COPY --from=ui-build /tmp/web/build ./public
2930
COPY --from=build /tmp/playground/server .
3031
COPY --from=build /tmp/playground/worker.wasm ./public
3132
COPY --from=build /tmp/playground/wasm_exec.js ./public
3233
EXPOSE 8000
33-
ENTRYPOINT /opt/playground/server -f=/opt/playground/data/packages.json -addr=:8000 -clean-interval=${APP_CLEAN_INTERVAL} -debug=${APP_DEBUG}
34+
ENTRYPOINT /opt/playground/server -f=/opt/playground/data/packages.json -addr=:8000 \
35+
-clean-interval=${APP_CLEAN_INTERVAL} -debug=${APP_DEBUG} -playground-url=${APP_PLAYGROUND_URL}

cmd/playground/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/x1unix/go-playground/pkg/analyzer"
1515
"github.com/x1unix/go-playground/pkg/compiler"
1616
"github.com/x1unix/go-playground/pkg/compiler/storage"
17+
"github.com/x1unix/go-playground/pkg/goplay"
1718
"github.com/x1unix/go-playground/pkg/langserver"
1819
"go.uber.org/zap"
1920
)
@@ -23,6 +24,7 @@ var Version = "testing"
2324

2425
type appArgs struct {
2526
packagesFile string
27+
playgroundUrl string
2628
addr string
2729
debug bool
2830
buildDir string
@@ -39,6 +41,7 @@ func main() {
3941
flag.StringVar(&args.addr, "addr", ":8080", "TCP Listen address")
4042
flag.StringVar(&args.buildDir, "wasm-build-dir", os.TempDir(), "Directory for WASM builds")
4143
flag.StringVar(&args.cleanupInterval, "clean-interval", "10m", "Build directory cleanup interval")
44+
flag.StringVar(&args.playgroundUrl, "playground-url", goplay.DefaultPlaygroundURL, "Go Playground URL")
4245
flag.BoolVar(&args.debug, "debug", false, "Enable debug mode")
4346

4447
goRoot, ok := os.LookupEnv("GOROOT")
@@ -80,6 +83,7 @@ func start(goRoot string, args appArgs) error {
8083

8184
zap.S().Info("Server version: ", Version)
8285
zap.S().Infof("GOROOT is %q", goRoot)
86+
zap.S().Infof("Playground url: %q", args.playgroundUrl)
8387
zap.S().Infof("Packages file is %q", args.packagesFile)
8488
zap.S().Infof("Cleanup interval is %s", cleanInterval.String())
8589
analyzer.SetRoot(goRoot)
@@ -98,7 +102,8 @@ func start(goRoot string, args appArgs) error {
98102
go store.StartCleaner(ctx, cleanInterval, nil)
99103

100104
r := mux.NewRouter()
101-
langserver.New(Version, packages, compiler.NewBuildService(zap.S(), store)).
105+
pg := goplay.NewClient(args.playgroundUrl, goplay.DefaultUserAgent, 15*time.Second)
106+
langserver.New(Version, pg, packages, compiler.NewBuildService(zap.S(), store)).
102107
Mount(r.PathPrefix("/api").Subrouter())
103108
r.PathPrefix("/").Handler(langserver.SpaFileServer("./public"))
104109

pkg/goplay/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
)
1414

1515
const (
16-
defaultUserAgent = "goplay.tools/1.0 (http://goplay.tools/)"
17-
playgroundUrl = "https://play.golang.org"
16+
DefaultUserAgent = "goplay.tools/1.0 (http://goplay.tools/)"
17+
DefaultPlaygroundURL = "https://play.golang.org"
1818

1919
// maxSnippetSize value taken from
2020
// https://github.com/golang/playground/blob/master/app/goplay/share.go
@@ -50,7 +50,7 @@ func NewClient(baseUrl, userAgent string, timeout time.Duration) *Client {
5050

5151
// NewDefaultClient returns Go Playground client with defaults
5252
func NewDefaultClient() *Client {
53-
return NewClient(playgroundUrl, defaultUserAgent, 15*time.Second)
53+
return NewClient(DefaultPlaygroundURL, DefaultUserAgent, 15*time.Second)
5454
}
5555

5656
func (c *Client) newRequest(ctx context.Context, method, queryPath string, body io.Reader) (*http.Request, error) {

pkg/goplay/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import (
88

99
func TestNewDefaultClient(t *testing.T) {
1010
c := NewDefaultClient()
11-
require.Equal(t, c.baseUrl, playgroundUrl)
12-
require.Equal(t, c.userAgent, defaultUserAgent)
11+
require.Equal(t, c.baseUrl, DefaultPlaygroundURL)
12+
require.Equal(t, c.userAgent, DefaultUserAgent)
1313
}

pkg/langserver/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ type Service struct {
3939
}
4040

4141
// New is Service constructor
42-
func New(version string, packages []*analyzer.Package, builder compiler.BuildService) *Service {
42+
func New(version string, playground *goplay.Client, packages []*analyzer.Package, builder compiler.BuildService) *Service {
4343
return &Service{
4444
compiler: builder,
4545
version: version,
46-
playground: goplay.NewDefaultClient(),
46+
playground: playground,
4747
log: zap.S().Named("langserver"),
4848
index: analyzer.BuildPackageIndex(packages),
4949
limiter: rate.NewLimiter(rate.Every(frameTime), compileRequestsPerFrame),

0 commit comments

Comments
 (0)