This is a Go project using Gin for REST API with route definitions directly in route.go
and MySQL integration.
- Go 1.16 or later
- MySQL database
The project uses the following Go packages:
github.com/gin-gonic/gin
: Web framework for building REST APIsgithub.com/go-sql-driver/mysql
: MySQL driver for Go's database/sql packagegopkg.in/yaml.v2
: YAML parser and emitter for Go
To run the project:
- Clone the repository.
git clone https://github.com/halowahyudi/rest-api-structure-golang.git
cd rest-api-structure-golang
- Set up your
config/config.yaml
file with your database and server details.database: user: your_db_user password: your_db_password host: localhost name: your_db_name server: port: "8080"
- Install dependencies using
go mod tidy
.go mod tidy
- Run the application using
go run cmd/app/main.go
.go run cmd/app/main.go
/ping
: GET endpoint to test if the server is running./dbtest
: GET endpoint to test if the database connection is working.