This project implements a backend server written in Go for a bookstore. It persists data in a mysql database (MariaDB) hosted locally on the machine. The server supports the following CRUD APIs:-
- Create book -> POST on /book
- Update book by ID -> PUT on /book/{Id}
- Read all books -> READ on /book
- Read book by ID -> READ on /book/{Id}
- Delete book by ID -> DELETE on /book/{Id}
These APIs have been tested and verified using postman
- Install MariaDB on your machine
- Create a Database 'bookstore'
- Run the following command in MariaDB to grant access to the database for a new user (which will be used by the Go project to access the database).
grant all on bookstore.* to '{yourUserName}'@localhost identified by '{yourPasswd}'
- Open the file /pkg/config/app.go
- Edit line 11 with {yourUserName} and {yourPasswd} set in step 3 as follows:-
d, err := gorm.Open("mysql", "{yourUserName}:{yourPasswd}@/bookstore?charset=utf8mb4&parseTime=True&loc=Local")
- Run "go build" in the /cmd/main directory in your terminal
- Run "go run main.go" command in the terminal
- Use postman to test the APIs defined above