A simple RESTful API built with Go and the Gin framework. This project serves as a boilerplate for creating web services with Gin.
- Lightweight and fast
- RESTful API design
- Easy routing with Gin
- Middleware support
- Simple error handling
- JSON response formatting
- JSON Logging support
- Go 1.20+
- Git
-
Clone the repository:
git clone git@github.com:chetuachar/gin-api-template.git cd gin-api-template -
Install dependencies:
go mod init gin-api-template go mod tidy
-
Add environment variables which are need to put below mentioned example environment
export VERSION=v1.0.0 export LOG_LEVEL=debug export LOG_STDOUT=false export LOG_FILE=gin-api.log export LOG_PATH=./log export LOG_MAX_SIZE=10 export LOG_MAX_BACKUPS=3 export LOG_MAX_AGE=7 export LOG_COMPRESS=false export SERVER_PORT=8086 export SELF_API_TOKEN=f144a0da7c41f4725d83c50ea4fdf1bd export REQ_RATE_LIMIT=10 export REQ_RATE_LIMIT_TIME=2 export LOG_SHOW_PASSWD=XyAdjllll
-
Run the API server:
go run main.go
-
Access the API at http://localhost:8086
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/hi |
Hi back |
| GET | /health |
Give you the api running status. |
| GET | /logs?passwd={password} |
Load the html template, (logging informations.) |
-
Getting information.
curl -X GET "https://<dns_name>/v1/hi" \ -H "Auth-Token: {token}" \ -H "Content-Type: application/json"
Complete project belonging to chethan nv @chetu_achar