Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: (How) Does the GopherJS playground handle includes? #73

Closed
Potherca opened this issue Aug 17, 2020 · 6 comments
Closed

Question: (How) Does the GopherJS playground handle includes? #73

Potherca opened this issue Aug 17, 2020 · 6 comments

Comments

@Potherca
Copy link

Potherca commented Aug 17, 2020

I have a simple piece of code.

When I run it in the Go Playground it works as expected.

However, when I run similar code in the GopherJS payground it gets an error:

failed to load package "github.com/asciitosvg/asciitosvg" 

Am I doing something wrong or does the GopherJS playground not support includes in the same way the Go Playground does?

Click to expand/collapse code
package main

import (
	"fmt"

	"github.com/asciitosvg/asciitosvg"
)

const logo = ` .-------------------------.
 |                         |
 | .---.-. .-----. .-----. |
 | | .-. | +-->  | |  <--+ |
 | | '-' | |  <--+ +-->  | |
 | '---'-' '-----' '-----' |
 |  ascii     2      svg   |
 |                         |
 '-------------------------'
https://github.com/asciit
osvg
[1,0]: {"fill":"#88d","a2s:delref":1}
`

func main() {

	input := []byte(logo)

	font := "Consolas,Monaco,Anonymous Pro,Anonymous,Bitstream Sans Mono,monospace" // Font family to use
	noBlur := false                                                                 // Disable drop-shadow blur
	scaleX := 9                                                                     // X grid scale in pixels
	scaleY := 16                                                                    // Y grid scale in pixels
	tabWidth := 8                                                                   // Tab width.

	canvas, err := asciitosvg.NewCanvas(input, tabWidth, true)

	if err == nil {
		svg := asciitosvg.CanvasToSVG(canvas, noBlur, font, scaleX, scaleY)

		fmt.Printf("%s\n", svg)
	}
}
@neelance
Copy link
Member

The GopherJS playground currently does not support importing packages that are not part of the standard library.

@Potherca
Copy link
Author

Do you happen to know if that is a design choice or if bringing the functionality up to date with the Go Playground (thus allowing includes) will be welcomed as a contribution?

@Potherca
Copy link
Author

Closing issue due to lack of activity.

@nevkontakte
Copy link
Member

@Potherca I only noticed this issue now, and I'm not the original author of the GopherJS playground, but I would guess that this is probably a technical limitation coming from the fact that the playground is purely client-side.

Standard library packages are precompiled and packaged ahead of time, which allows them to be used. However, to import third-party packages, some kind of backend would have to be implemented and, more importantly, paid for. I presume the latter is why it wasn't done.

@dmitshur
Copy link
Member

dmitshur commented Jun 13, 2022

Also see #26.

Its "Implementation" section discussed two approaches, though more relevant to the GOPATH mode. The Go module mode was added 3 years later and creates new possibilities to fetch dependencies. The module mirror also allows CORS requests. So more frontend heavy implementations (i.e., the GopherJS Playground could download and compile third party dependencies... inside the user's browser) should also be viable now.

@Potherca
Copy link
Author

Thanks for the clarification @nevkontakte and @dmitshur!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants