Golang CRUD with PostgreSQL
👀
Table of contents
General info
GOPOST or Go-Post is a Golang REST API made to show some indetity for person.
🍵
The GOPOST Object Properties | Description | Type |
---|---|---|
name | the identity name | String |
location | location from the identity | String |
age | the age of identity | Int64 |
⚡
Routes Routes | HTTP Methods | Description |
---|---|---|
/api/user/ | GET | Displays all identity |
/api/newuser/ | POST | Creates a new identity |
/api/deleteuser/ | DELETE | Deletes all tea |
/api/user/{id} | GET | Displays a specific tea, given its name |
/api/user/{id} | PUT | Update identitiy Value |
/api/user/{id}} | DELETE | Deletes a specific identity, given its id |
Technologies
Project is created with:
- Golang
- gorilla/mux
- lib/pq
- joho/godotenv
- ElephantSQL
How I built it
Setup
To run this project locally, clone repo and add an .env
file in the root:
POSTGRES_URL="Postgres connection string"
Then execute in command prompt:
$ cd go-post
$ go mod tidy
$ go run main.go
API Reference
These are the endpoints available from the app
GET /api/user/
Returns result identity
Response
Show example response
{
"data": [
{
"id":40,
"name":"hafizh",
"location": "widodo",
"age":22,
}
]
}
POST /api/newuser/
Creates a new identity
Request
This request requires body payload, you can find the example below.
Show example payload
{
"name":"hafizh",
"location":"kansas",
"age":12
}
GET /players/:id
Returns a player by id
Response
Show example response
{
"meta": {
"code": 200
},
"data": {
"id": "5f6a5c31d7c451c369802c02",
"name": "John Doe 1",
"nickname": "Lolo",
"position": "forward",
"created_at": "2020-09-22T20:18:57.957Z"
}
}
GET /players/:id
Returns a player by id
Response
Show example response
{
"meta": {
"code": 200
},
"data": {
"id": "5f6a5c31d7c451c369802c02",
"name": "John Doe 1",
"nickname": "Lolo",
"position": "forward",
"created_at": "2020-09-22T20:18:57.957Z"
}
}
UPDATE /api/user/:ID
Update value of identity
Response
Show example response
{
"name": "hafizah",
"location": "toronto",
"age": 25,
}
DELETE /api/user/
Delete all team
DELETE /api/user/:ID
Delete team by id