Deploy a Go application on onesubnet
Compile and run a Go binary: build, port via env, environment variables and logs.
Deploy a Go application on onesubnet
onesubnet compiles your Go binaries and runs them. Deploy via Git from the panel.
1. Prepare the project
- A
go.modat the root (go mod init myapp). - Make your server listen on the port from the
PORTvariable:
port := os.Getenv("PORT")
if port == "" { port = "8080" }
http.ListenAndServe(":"+port, nil)
2. Deploy
- Connect your Git repository in the panel.
- Build command:
go build -o app ./... - Start command:
./app
3. Environment variables
Set PORT, DATABASE_URL, etc. in Settings → Environment.
4. Logs
Live console in the panel. For structured logs, use the log/slog package (Go 1.21+).
References
- Go docs: https://go.dev/doc/
- Go modules: https://go.dev/blog/using-go-modules