This is a sample application that uses the gorilla/mux router and Postgres for database operations. The application is a simple product catalog that allows you to add products, fetch all products, and fetch a single product.
git clone https://github.com/keploy/samples-go.git && cd samples-go/mux-sql
go mod downloadUsing the docker-compose file we will start our postgres instance:-
# Start Postgres
docker-compose up -d postgresSince we have setup our sample-app natively set the host to
localhoston line 10.
Now, we will create the binary of our application:-
go build -covercurl --request POST \
--url http://localhost:8010/product \
--header 'content-type: application/json' \
--data '{
"name":"Bubbles",
"price": 123
}'this will return the response.
{
"id": 1,
"name": "Bubbles",
"price": 123
}
curl --request GET \
--url http://localhost:8010/productswe will get output:
[{"id":1,"name":"Bubbles","price":123},{"id":2,"name":"Bubbles","price":123}]curl --request GET \
--url http://localhost:8010/product/1
we will get output:-
```json
{"id":1,"name":"Bubbles","price":123}