Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Making some changes for GopherJS playground update#1404

Merged
grantnelson-wf merged 1 commit intogopherjs:masterfrom
Workiva:addWriteSyncHook
Jan 23, 2026
Merged

Making some changes for GopherJS playground update#1404
grantnelson-wf merged 1 commit intogopherjs:masterfrom
Workiva:addWriteSyncHook

Conversation

@grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Jan 22, 2026

I'm making three changes that will help me with the GopherJS playground update that I've been slowly working on:

  1. Adding an indent to some of the JS output so that non-minified looks prettier

  2. Adding a WriteSync hook so that we can redirect the output from os.Stdout and os.Stderr to another location other than console.log when not running in node.js. This allows us to redirect the output from fmt.Print to the text box in the playground. To use the hook we just have to set a function like:

        js.Global.Set(`gopherjsWriteSyncHook`, func(fd int, text string) {
             // write somewhere else
        })
    • Obviously, do not call fmt.Print or anything like that from inside that function otherwise it will get stuck in an infinite loop
    • The fd is so that we can color the output, send errors to somewhere different from text, or whatever we want. When the hook is set the buffer is skipped so that we're not mixing Stdout and Stderr text together based on which ever had a newlines. If the hook is set while there is text in the buffer, the buffer is just flushed out with the fd for the last print which might not be correct for the text that was in the buffer, but it's close enough. We could also just remove the fd if you think that's not useful or skip the buffering.
    • This change will take the place of goPrintToConsole that the playground used to use but it doesn't appear be anything anymore
    • For the playground I also tried to set a custom fs or have fs available via require but those were a lot of work and ended up not working correctly, so this is the simpler straight forward approach. If you have any other ideas you'd like me to explore first, I'm up for other ways to make this hook work.
  3. Moving the Error List out from an internal package so that the error can be broken up into the list of errors

@grantnelson-wf grantnelson-wf self-assigned this Jan 22, 2026
@grantnelson-wf grantnelson-wf force-pushed the addWriteSyncHook branch 2 times, most recently from 2ded891 to d212276 Compare January 23, 2026 00:08
@grantnelson-wf grantnelson-wf merged commit 346e3e9 into gopherjs:master Jan 23, 2026
10 checks passed
@grantnelson-wf grantnelson-wf deleted the addWriteSyncHook branch January 23, 2026 15:51
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

Successfully merging this pull request may close these issues.

2 participants