没有不值得去解决的问题,也没有不值得去学习的技术!

The “A Tour of Go” Multilingual Translation Project: Switching Production Run / Format to ZgoCloud Execution Nodes

Figure 3: After purging the /tour/script.js cache, Run directly requests ZgoCloud /compile and returns HTTP 200

作者:

在

The previous article completed the setup of the ZgoCloud Playground execution node.

The new execution interfaces are ready:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/compile
https://play.go-dev.shuijingwanwq.com:8443/fmt

They are statically forwarded to the official Go Playground:

Plaintext
https://play.golang.org/compile
https://play.golang.org/fmt

However, reaching this step only solves the problem of “the new execution node is now working.”

In the production environment, the A Tour of Go browser code still uses the original same-origin interfaces:

Plaintext
/_/compile
/_/fmt

In other words, the actual request path is still:

Plaintext
Browser
→ EdgeOne
→ Alibaba Cloud
→ Go Tour
→ go.dev Playground

This article continues to document the second phase:

How to actually switch Run and Format in the production environment to the new ZgoCloud execution node, and why, after deployment, the browser temporarily continued executing the old logic even though the new version had been successfully deployed.


1. First, confirm exactly how the production environment executes code

Before making any formal changes, I had Codex perform a read-only audit on go-tour-i18n.

Rather than rushing to modify the code, this round focused on thoroughly mapping out the request paths for Run, Format, local preview, and production.

The results were slightly more complex than initially imagined.

Run in the production environment uses:

Plaintext
HTTPTransport

Ultimately initiated by _content/js/playground.js:

Plaintext
POST /_/compile?backend=...

However, Format does not entirely use the same HTTPTransport.

There are actually two places in the repository that make Format requests:

Plaintext
_content/js/playground.js
_content/tour/static/js/services.js

They both ultimately request:

Plaintext
/_/fmt

Therefore, if only Run is modified, it easily leads to:

Plaintext
Run     → new execution node
Format  → still requests the old interface

This kind of half-migrated state.


2. Local preview and production cannot be modified together

The audit also confirmed a very important distinction.

Local preview uses:

Plaintext
SocketTransport

Via:

Plaintext
/socket

To connect to the local runtime environment.

While production uses:

Plaintext
HTTPTransport

And the production environment has explicitly disabled:

Plaintext
/socket
/socket/

Both of these paths return in production:

Plaintext
404

So this change cannot simply globally replace all:

Plaintext
/_/compile
/_/fmt

With external URLs.

What I want to ultimately achieve is:

Plaintext
Production:
Run    → ZgoCloud /compile
Format → ZgoCloud /fmt

Local preview:
Continue using SocketTransport

While preserving the original relative path behavior, leaving room for compatibility and rollback.


3. Add a unified Playground base URL

The final approach adopted is to add a unified configuration during page initialization:

JavaScript
window.playgroundBaseURL

Production injects:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443

While local preview keeps:

Plaintext
""

Which is an empty string.

Then, a very small URL handling function was added.

The logic is roughly:

Plaintext
If playgroundBaseURL is empty:
    Keep the original path

If playgroundBaseURL is configured:
    Use the external base URL

This way, the original calls can still be written as:

Plaintext
/_/compile
/_/fmt

But in the production environment, they will ultimately generate:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/compile
https://play.go-dev.shuijingwanwq.com:8443/fmt

And when no external base URL is configured, they remain:

Plaintext
/_/compile
/_/fmt

4. Why the external interface no longer uses /_/

A small adjustment was made here midway through.

Initially, to maximize compatibility with the original A Tour of Go request paths, ZgoCloud was also temporarily designed to use:

Plaintext
/_/compile
/_/fmt

Later, I re-examined the official interfaces:

Plaintext
go.dev
→ /_/compile
→ /_/fmt

While the direct Playground interfaces are actually:

Plaintext
play.golang.org/compile
play.golang.org/fmt

Therefore, there was no need for the new standalone execution service to continue inheriting the /_/ path layer.

The final external interfaces were unified to:

Plaintext
/compile
/fmt

This makes the entire structure more direct:

Plaintext
play.go-dev.shuijingwanwq.com:8443/compile
→ play.golang.org/compile

And:

Plaintext
play.go-dev.shuijingwanwq.com:8443/fmt
→ play.golang.org/fmt

The old same-origin interfaces remain:

Plaintext
/_/compile
/_/fmt

The responsibilities of the two sets of interfaces are thus easier to distinguish.


5. Run and both Format locations must be switched together

After the modifications were completed, all three request locations in the production environment use the same base URL rule.

Run:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/compile?backend=...

Format in the Playground editor:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/fmt?backend=...

Format in the course page service:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/fmt

Here:

Plaintext
backend

Is still just a normal query parameter.

It does not participate in the selection of:

Plaintext
scheme
host
port

Therefore, this parameter cannot be used to change the request target.


6. The production base URL must also consider JavaScript string safety

This round also addressed a very easily overlooked issue.

The production base URL will ultimately end up in:

JavaScript
window.playgroundBaseURL = ...

So the configuration cannot simply be injected into JavaScript using string concatenation.

Ultimately, Go’s:

Go
encoding/json.Marshal

Was used to generate a JSON string literal that is safe for JavaScript to use.

During testing, special values like the following were specifically used for validation:

Plaintext
https://example.test/";alert(1)//</script>

json.Marshal correctly handles:

Plaintext
"
\
<
>
&

And other such characters.

For example:

Plaintext
<
→ \u003c

>
→ \u003e

Midway through, a test failed because the hand-written escape expectations missed the > for:

Plaintext
\u003e

Ultimately, it was confirmed that the implementation itself had no issues; only the test was fixed to validate directly against the actual output of json.Marshal.


7. The old server-side Playground interfaces have not been deleted yet

Although the production browser is now ready to access ZgoCloud directly, I did not immediately delete the original ones in the Alibaba Cloud Go Tour:

Plaintext
/_/compile
/_/fmt

They are still retained for:

Plaintext
Browser or other compatible requests
→ Alibaba Cloud Go Tour
→ go.dev

This is no longer the main path for normal production Run / Format, but serves temporarily as:

Plaintext
Compatibility
Rollback

Capabilities.

The focus of this migration is:

First, stabilize and deploy the new browser execution path, and then consider whether to remove the old implementation later.

This way, if unexpected issues occur after the new path goes live, there is still a relatively simple path to recovery.


8. Only commit after all tests pass

This round ultimately modified 9 files:

Plaintext
_content/js/playground.js
_content/tour/static/js/page.js
_content/tour/static/js/services.js
internal/tour/appengine.go
internal/tour/local.go
internal/tour/production.go
internal/tour/production_test.go
internal/tour/server_test.go
internal/tour/tour.go

Tests included:

Plaintext
Production injects the correct Playground base URL
Local preview does not inject the production URL
Production continues to use HTTPTransport
Local continues to use SocketTransport
Production /socket continues to return 404
Run ultimately generates ZgoCloud /compile
Both Format locations ultimately use ZgoCloud /fmt
When the base URL is empty, /_/compile and /_/fmt are still preserved
backend cannot change the request host
JavaScript string safety escaping

Finally:

Bash
go test ./internal/tour

Passed.

Full:

Bash
go test ./...

Also all passed.

Committed as:

Plaintext
ffbb8ce
feat: production browser directly connects to Playground proxy

9. The release manifest must also be updated synchronously

After the code switch was completed, I found a leftover issue at the release level.

release.json still recorded:

JSON
{
  "execution_transport": "http-playground-proxy",
  "execution_provider": "go.dev"
}

Normal execution has now ultimately fallen to:

Plaintext
play.golang.org

So:

Plaintext
execution_provider

Can no longer be written as:

Plaintext
go.dev

Finally adjusted to:

JSON
{
  "execution_transport": "http-playground-proxy",
  "execution_provider": "play.golang.org",
  "local_socket_enabled": false
}

Here:

Plaintext
execution_transport = http-playground-proxy

Is still retained.

Because the browser still uses HTTPTransport and calls the official execution service via the fixed Playground forwarding node.

At the same time, it was also necessary to modify:

Plaintext
scripts/deploy-production.sh

Because the deployment script previously also validated:

Plaintext
execution_provider = go.dev

If only the manifest is changed without updating the deployment pre-check, the new release would be rejected by its own production deployment script.

This round synchronously modified:

Plaintext
publish.go
publish_test.go
deploy-production.sh
README.md
PROJECT_STATE.md

And completed full testing once again.


10. Generate the new production bundle

The final production bundle is:

Plaintext
/tmp/go-tour-release-20260813-zh-CN-1fe73f5

Corresponding project commit:

Plaintext
1fe73f54615b3d05d09133f6e25aa91c5fb07f75

Release status:

Plaintext
ready=103
pending=0
blocked=0
pages=103
articles=7

release.json has correctly recorded:

JSON
{
  "execution_transport": "http-playground-proxy",
  "execution_provider": "play.golang.org",
  "local_socket_enabled": false
}

All bundle files have been re-verified with SHA-256 checksums.

The production binary remains:

Plaintext
Linux amd64
Statically linked
CGO_ENABLED=0

11. Automatic deployment succeeded

The new release was then officially deployed via the existing automated deployment script.

Final production directory:

Plaintext
/data/go-tour/releases/20260813-zh-CN-1fe73f5

Deployment process completed:

Plaintext
Local bundle pre-check
Remote upload
Remote SHA-256 verification
Permission normalization
Atomic current switch
go-tour.service restart
localhost health check
Public domain acceptance

During the first health check right after the service restarted, it showed:

Plaintext
service=active
HTTP=000

Subsequently:

Plaintext
active + HTTP 200
active + HTTP 200
active + HTTP 200

After passing three consecutive times, the deployment was officially deemed successful.

Finally:

Plaintext
deployment completed
public acceptance passed

At this point, from the server side, the new release had successfully gone live.

But the truly interesting problem had just emerged.


12. The new release is live, so why is the browser still requesting the old interface?

I then opened Firefox and navigated to:

Plaintext
https://go-dev.shuijingwanwq.com/tour/welcome/1

Opened the Developer Tools Network panel, and then clicked “Run”.

The page output normally:

Plaintext
Hello, 世界
Program exited.

But the request shown in the Network panel was still:

Plaintext
POST https://go-dev.shuijingwanwq.com/_/compile?backend=
Figure 1: The new release has been deployed, but the browser's first acceptance still requests the old /_/compile
Figure 1: The new release has been deployed, but the browser’s first acceptance still requests the old /_/compile

This was very strange.

Because:

  • The new code had been committed;
  • The new production bundle had been regenerated;
  • current had been switched;
  • go-tour.service had been restarted;
  • The public web page was returning 200.

Looking only at the deployment results, it would be easy to keep suspecting:

Plaintext
Did the production binary not update?
Was the JS not included in the bundle?
Did the initScript injection fail?

But the real cause was not in the Go Tour.


13. The real issue was that EdgeOne cached the old /tour/script.js

The browser execution logic for A Tour of Go ultimately comes from:

Plaintext
/tour/script.js

Although the new production release had been switched, the EdgeOne nodes might still be holding a previous version of this script.

So the browser was getting:

Plaintext
Old HTML / New service
+
Old script.js

The old JavaScript naturally still executed:

Plaintext
/_/compile
/_/fmt

After finally confirming the issue, I did not flush the entire site cache, but only targeted:

Plaintext
https://go-dev.shuijingwanwq.com/tour/script.js

For a targeted cache purge.

Figure 2: Targeted cache purge for /tour/script.js in EdgeOne
Figure 2: Targeted cache purge for /tour/script.js in EdgeOne

This is well worth remembering going forward:

A successful production release switch does not mean the browser is necessarily executing the new front-end code.

As long as the CDN retains old dynamic script resources, the behavior the browser sees may still belong to the previous version.


14. After refreshing /tour/script.js, the new execution path took effect immediately

After the targeted EdgeOne cache purge, I reloaded the course page.

Clicked “Run” again.

This time, the Firefox Network panel showed:

Plaintext
POST https://play.go-dev.shuijingwanwq.com:8443/compile?backend=

Status:

Plaintext
HTTP 200

Protocol:

Plaintext
HTTP/2

The page output was still normal:

Plaintext
Hello, 世界
Program exited.
Figure 3: After purging the /tour/script.js cache, Run directly requests ZgoCloud /compile and returns HTTP 200
Figure 3: After purging the /tour/script.js cache, Run directly requests ZgoCloud /compile and returns HTTP 200

The CORS in the response was also as expected:

Plaintext
access-control-allow-origin:
https://go-dev.shuijingwanwq.com

At this moment, it was finally possible to confirm:

The production browser Run no longer goes through the Alibaba Cloud Go Tour’s /_/compile.


15. Format has also completed the real browser switch

After Run passed, I continued to test “Format”.

The actual Format request had changed to:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/fmt

It also returned successfully.

Therefore, the final two normal production execution paths are respectively:

Plaintext
Run
Browser
→ ZgoCloud /compile
→ play.golang.org/compile

And:

Plaintext
Format
Browser
→ ZgoCloud /fmt
→ play.golang.org/fmt

This step was very important.

Because the earlier code audit revealed that Run and Format do not have just a single unified request point.

Only after all three browser requests were correctly switched could the entire execution path migration be considered complete.


16. Page traffic and execution traffic are now truly separated

After completing this migration, the production environment effectively formed two completely different paths.

Normal page access:

Plaintext
Browser
→ EdgeOne
→ Alibaba Cloud Nginx
→ Go Tour

Code Run:

Plaintext
Browser
→ play.go-dev.shuijingwanwq.com:8443/compile
→ ZgoCloud Nginx
→ play.golang.org/compile

Format:

Plaintext
Browser
→ play.go-dev.shuijingwanwq.com:8443/fmt
→ ZgoCloud Nginx
→ play.golang.org/fmt

In other words:

Alibaba Cloud is now primarily responsible for page serving and no longer handles remote Playground forwarding for normal Run / Format.

The production server still does not execute user-submitted Go programs locally.


17. The experience of real public network testing on mobile has also noticeably improved

After completing the desktop Firefox acceptance, I went ahead and tested directly on a mobile device.

No additional network tools were used this time.

I directly opened the production version of A Tour of Go and clicked “Run”.

The actual experience was:

After clicking, the execution result returned basically very quickly.

This result is very meaningful to me.

Because the server-side:

Plaintext
curl

Test only proves that:

Plaintext
ZgoCloud
→ play.golang.org

Is working normally.

The desktop Network further proves that:

Plaintext
Browser
→ ZgoCloud

Has actually taken effect.

The actual usage in the mobile device’s real network environment further validated this complete path:

Plaintext
Mobile browser
→ ZgoCloud
→ play.golang.org

Can indeed return quickly under this test environment.

Of course, a single real-world usage cannot prove that the same performance will definitely be maintained in all regions, on all networks, and at all times.

But combined with:

Plaintext
ZgoCloud 100 consecutive test rounds
Desktop Firefox HTTP/2 acceptance
Mobile real public network experience

There is already multi-layered evidence indicating that this adjustment direction is effective.


18. The old Alibaba Cloud execution interfaces are temporarily retained

Currently, the Alibaba Cloud Go Tour still retains:

Plaintext
/_/compile
/_/fmt

And the corresponding:

Plaintext
https://go.dev/_

Server-side forwarding logic.

But the normal production browser will no longer use them.

I am not in a rush to delete them right now.

The reason is simple:

There is no need to immediately clean up compatibility and rollback capabilities that are already running stably just as the new path goes live.

It will be more prudent to wait until the new execution path has been running for a while before deciding whether to further reduce functionality.

So the current state is:

Plaintext
New path:
Officially in use

Old path:
Retained, but not serving as the normal browser execution path

19. The most memorable part this time is not the code, but the CDN cache

The code modifications themselves were not actually that complex this time.

What is truly easy to misjudge is:

Plaintext
Git commit successful
→ production bundle successful
→ automatic deployment successful
→ current switched
→ service restarted
→ official site HTTP 200

After all of these succeed:

The browser may still be executing old code.

Because the JavaScript that the user actually runs still goes through the CDN.

Therefore, going forward, as long as a release involves:

Plaintext
/tour/script.js

Or other resources that determine front-end behavior, it is not enough to just look at:

Plaintext
systemd
curl localhost
Official homepage HTTP status code

You must also open the browser Network panel and confirm:

Where the actual requests are really being sent.

If the Network panel hadn’t been checked this time, and only the page output was observed:

Plaintext
Hello, 世界

The fact that the execution path was still the old one would never have been discovered.


20. Final status

As of the completion of this release, the official production release is:

Plaintext
/data/go-tour/releases/20260813-zh-CN-1fe73f5

Corresponding code:

Plaintext
1fe73f54615b3d05d09133f6e25aa91c5fb07f75

Release status:

Plaintext
ready=103
pending=0
blocked=0
pages=103
articles=7

Release manifest:

Plaintext
execution_transport=http-playground-proxy
execution_provider=play.golang.org
local_socket_enabled=false

Real production acceptance:

Plaintext
Run     → ZgoCloud /compile → HTTP 200
Format  → ZgoCloud /fmt     → Success
CORS    → Normal
/socket → 404

Mobile real public network Run:

Plaintext
Success
And response was fast in this experience

At this point:

The migration of the A Tour of Go production Playground execution path to the fixed ZgoCloud execution node is complete.


Summary

On the surface, this migration simply changed:

Plaintext
/_/compile
/_/fmt

To:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/compile
https://play.go-dev.shuijingwanwq.com:8443/fmt

But once fully carried out, it actually involved:

Plaintext
Existing production request path audit
Production and local runtime mode distinction
Unification of Run and both Format requests
JavaScript configuration safety injection
CORS
Release manifest
Production deployment pre-check
Production bundle
Automated deployment
CDN cache
Browser Network acceptance
Mobile real-world usage acceptance

The resulting architecture is also clearer than before.

Pages handle pages:

Plaintext
Browser
→ EdgeOne
→ Alibaba Cloud
→ Go Tour

Execution handles execution:

Plaintext
Browser
→ ZgoCloud
→ play.golang.org

The two parts are no longer tightly bound to the same network path.

And the most valuable lesson from this deployment process, I believe, is not any specific piece of code, but rather:

When front-end behavior changes, a successful production deployment does not mean users have already received the new code. Final acceptance must ultimately fall on the real requests in the browser Network panel.

Only after seeing:

Plaintext
https://play.go-dev.shuijingwanwq.com:8443/compile

Actually appear in the browser’s request list can this migration be considered truly complete.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系