Urgent.News

What's breaking now, across hundreds of outlets.

Tech

What a Go App Needs Before You Deploy It (with a ShardCloud Walkthrough)

go run . works on your laptop. Then you upload your app and the build log says undefined: writeJSON . Or the build succeeds, but your public URL returns 502 Bad Gateway . Those failures happen at different points. In the first case, the platform never started the app. In the second, the proxy couldn't get a response from it. We'll deploy a small API using Go's standard library, then use the build…

Deploying a Go application requires careful consideration of several factors before going live. A Go application that runs locally on your laptop may encounter different issues when deployed to a hosting platform. Two common problems are the platform failing to start the app or the proxy not receiving a response from it. To differentiate between these issues, we'll deploy a small API using Go's standard library and analyze the build and startup logs.

In Go, a package build and a file build can include different code. The `go run .` command executes the package in the current directory, allowing it to pick up both `main.go` and `handlers.go`. When using `MAIN=main.go`, ShardCloud builds the `main.go` file as the entry point. If your package spans multiple files, a package build should be used instead.

To ensure smooth deployment, it's essential to include the `go.mod` file with the source code. The `go directive` in `go.mod` sets the minimum Go version required by the project. Choose a platform runtime that is equal to or newer than this version. If third-party dependencies are added, run `go mod tidy` and include the resulting `go.sum` file when Go creates it. In this example, only the standard library is used.

When listening on the platform's port, read the `PORT` environment variable and use an address like `:8080`. Leaving the host empty allows Go to listen on all network interfaces. A small Go API can be built by creating a folder named `hello-go` and defining the necessary files. Make sure to have Go 1.27 or newer installed locally and a ShardCloud account for the upload process.

The `go.mod` file should include the module name, Go version, and main package. For this example, the module name is `example.com/hello-go`, the Go version is `1.27.0`, and the main package is `main.go`. The `main.go` file should contain the necessary code to handle HTTP requests and respond with JSON data. The `writeJSON` function is responsible for setting the content type and encoding the response body.

To deploy the API to ShardCloud, add `.shardcloud` next to `go.mod` and `main.go`. Set `DISPLAY_NAME` to a desired name for the application, `MAIN` to `main.go`, `MEMORY` to the desired memory allocation, `VERSION` to the Go version, and `SUBDOMAIN` to an available subdomain. ShardCloud will compile the source code and start the resulting binary, setting `PORT=80` for the code to read on startup.

Create a ZIP archive from inside the project folder containing the source code, `go.mod`, and `.shardcloud` configuration file. On macOS or Linux, use the `zip` command, while on Windows, use the `tar` command with PowerShell. Once the ZIP archive is created, upload it to the ShardCloud dashboard under the "Applications" section. Choose "New app" and upload the `hello-go.zip` file.

After uploading the application, check the logs for the message "Listening on :80" and open the application's health endpoint (`/health`) on the .shardweb.app URL to verify a successful HTTP 200 response with the expected JSON data. If any build failures or 502 errors occur, diagnose the issue by examining the logs and adjusting the configuration as needed.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

How I Set Up OpenCode: A Real Agent OS (Config, Skills, MCPs, Memory)

🧠 How I Set Up OpenCode: A Real Agent OS (Config, Skills, MCPs, Memory) You have inherited a repository. At a glance: 1 config file · 40+ subagents · 123 skills · 20 commands · 8 MCP servers · 2…

  • Author sets up OpenCode, a real agent OS with config, skills, MCPs, and memory.
  • Setup features two-layer memory pipeline, deterministic file protocol, and clear project layout.

What the 2025 EU MRV cohort actually shows: CII band movement and FuelEU gaps

Syndicated copy. Canonical version: ingeniat.pro . Set the publishing platform's canonical link to that URL. The 2025 public EU MRV snapshot is more than a downloadable table.

  • 66.9% of vessels retained their band ranking from 2024 to 2025
  • 14,321 vessel profiles passed FuelEU screening, 99.7% of total
  • Gas carriers showed the largest median GHG intensity gap at -9.3%

More from Sunday, 29 November 2026 →