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

Compile from string? #961

Closed
yjp20 opened this issue Feb 1, 2020 · 2 comments
Closed

Compile from string? #961

yjp20 opened this issue Feb 1, 2020 · 2 comments
Labels

Comments

@yjp20
Copy link

@yjp20 yjp20 commented Feb 1, 2020

I have a strange use case of gopherjs where I want to take a map[string]string mapping the file name to the file contents and use that to compile to javascript in the form of a string. I've looked around for a few hours and the best resources I've found were the gopherjs/build package and the gopherjs playground, but not knowing exactly how everything works it's a bit much to digest.

If it isn't too much to ask, would it be possible to add support for this kind of parsing or help me with a snippet that can achieve the function?

@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Feb 8, 2020

I think what you're looking for is available in the package github.com/shurcooL/gopherjslib. If you have a files map[string]string, then you can do:

var out bytes.Buffer
builder := gopherjslib.NewBuilder(&out, nil)
for name, src := range files {
	builder.Add(name, strings.NewReader(src))
}
err := builder.Build()
// Use out ...
@dmitshur dmitshur added the question label Feb 8, 2020
@yjp20

This comment has been minimized.

Copy link
Author

@yjp20 yjp20 commented Feb 8, 2020

Ah, that was what I was looking for. Thanks :)

@yjp20 yjp20 closed this Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.