Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ WORKDIR /opt/playground
ENV GOROOT /usr/local/go
ENV APP_CLEAN_INTERVAL=10m
ENV APP_DEBUG=false
ENV APP_PLAYGROUND_URL=https://play.golang.org
COPY data ./data
COPY --from=ui-build /tmp/web/build ./public
COPY --from=build /tmp/playground/server .
COPY --from=build /tmp/playground/worker.wasm ./public
COPY --from=build /tmp/playground/wasm_exec.js ./public
EXPOSE 8000
ENTRYPOINT /opt/playground/server -f=/opt/playground/data/packages.json -addr=:8000 -clean-interval=${APP_CLEAN_INTERVAL} -debug=${APP_DEBUG}
ENTRYPOINT /opt/playground/server -f=/opt/playground/data/packages.json -addr=:8000 \
-clean-interval=${APP_CLEAN_INTERVAL} -debug=${APP_DEBUG} -playground-url=${APP_PLAYGROUND_URL}
7 changes: 6 additions & 1 deletion cmd/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/x1unix/go-playground/pkg/analyzer"
"github.com/x1unix/go-playground/pkg/compiler"
"github.com/x1unix/go-playground/pkg/compiler/storage"
"github.com/x1unix/go-playground/pkg/goplay"
"github.com/x1unix/go-playground/pkg/langserver"
"go.uber.org/zap"
)
Expand All @@ -23,6 +24,7 @@ var Version = "testing"

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

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions pkg/goplay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

const (
defaultUserAgent = "goplay.tools/1.0 (http://goplay.tools/)"
playgroundUrl = "https://play.golang.org"
DefaultUserAgent = "goplay.tools/1.0 (http://goplay.tools/)"
DefaultPlaygroundURL = "https://play.golang.org"

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

// NewDefaultClient returns Go Playground client with defaults
func NewDefaultClient() *Client {
return NewClient(playgroundUrl, defaultUserAgent, 15*time.Second)
return NewClient(DefaultPlaygroundURL, DefaultUserAgent, 15*time.Second)
}

func (c *Client) newRequest(ctx context.Context, method, queryPath string, body io.Reader) (*http.Request, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/goplay/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (

func TestNewDefaultClient(t *testing.T) {
c := NewDefaultClient()
require.Equal(t, c.baseUrl, playgroundUrl)
require.Equal(t, c.userAgent, defaultUserAgent)
require.Equal(t, c.baseUrl, DefaultPlaygroundURL)
require.Equal(t, c.userAgent, DefaultUserAgent)
}
4 changes: 2 additions & 2 deletions pkg/langserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ type Service struct {
}

// New is Service constructor
func New(version string, packages []*analyzer.Package, builder compiler.BuildService) *Service {
func New(version string, playground *goplay.Client, packages []*analyzer.Package, builder compiler.BuildService) *Service {
return &Service{
compiler: builder,
version: version,
playground: goplay.NewDefaultClient(),
playground: playground,
log: zap.S().Named("langserver"),
index: analyzer.BuildPackageIndex(packages),
limiter: rate.NewLimiter(rate.Every(frameTime), compileRequestsPerFrame),
Expand Down