Simple starter project using Gin
- Root endpoint:
GET /→ returns a welcome JSON message. - Health endpoint:
GET /health→ returns application status and uptime. - Status/ping endpoint:
GET /status→ returns HTTP 200 OK. - Middleware: Gin
LoggerandRecovery. - Graceful shutdown when receiving OS signals (CTRL+C, SIGTERM, etc).
Make sure Go is installed (recommended Go 1.22+).
cp .env.example .env # create .env from the template
# open .env and adjust the PORT value, for example:
# PORT=8080
go mod tidy
go run main.goBy default the server runs at http://localhost:3000 (or according to the PORT value in .env).
.env.exampleis the environment template:- Copy it to
.envwith the command above. - Change the
PORTvalue in.envas needed (e.g. 8080, 5000, etc.).
- Copy it to
- The application will:
- Load the
.envfile at startup. - Read the
PORTvariable. - If
PORTis not set, it will fall back to3000.
- Load the
-
GET /-
Example response:
{ "message": "Welcome to Go Gin Starter" }
-
-
GET /health-
Example response:
{ "status": "ok", "uptime": "10s" }
-
-
GET /status- Response is HTTP 200 with an empty body.