Deploy Go
1. Prepare Your Project
Ensure your app reads the PORT environment variable:
main.go
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from Espace-Tech Cloud!")
})
fmt.Printf("Server running on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}2. Initialize
cd my-go-app
espacetech initespacetech.json
{
"name": "my-go-app",
"framework": "go",
"build_command": "go build -o app .",
"start_command": "./app",
"port": 8080
}3. Deploy
espacetech deployWith Gin Framework
package main
import (
"os"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "Hello from Espace-Tech Cloud!"})
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
r.Run(":" + port)
}Add a Database
espacetech db create my-db
espacetech db link my-db --project my-go-appimport "os"
dbURL := os.Getenv("DATABASE_URL")
// Use with pgx, GORM, sqlx, etc.