Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hylim-tech-lover/restful-services-go
Dockerized RESTful services in Go
https://github.com/hylim-tech-lover/restful-services-go
docker dockerfile go-fiber golang gorm-postgresql-driver
Last synced: about 1 month ago
JSON representation
Dockerized RESTful services in Go
- Host: GitHub
- URL: https://github.com/hylim-tech-lover/restful-services-go
- Owner: hylim-tech-lover
- License: mit
- Created: 2022-12-14T10:10:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-14T14:59:33.000Z (about 2 years ago)
- Last Synced: 2024-10-18T17:13:20.063Z (3 months ago)
- Topics: docker, dockerfile, go-fiber, golang, gorm-postgresql-driver
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dockerized RESTful services in Go
## Environment Setup / Pre-requisite
> Please install the following for running OS environment before continue:
1. [Go](https://go.dev/doc/install)
2. [Docker](https://www.docker.com/products/docker-desktop/)
3. [Postman](https://www.postman.com/downloads/)---
## Quick Start
1. Git clone current repository to your local environment and open with preferred IDE [eg: VS code].
2. Rename [.env.example](./.env.example) to `.env` file .
3. Make sure `no other application` running at port `3000` as it will be used by the application.
4. Make sure docker is already running at local environment.
5. Open terminal in `project root path` and run following command to verify docker are running:```bash
# View installed docker version
docker version
```6. If docker is not running, please run docker and repeat Step 5.
7. At the terminal, run following command to start `containerized RESTful services` in Go with Postgres database via Docker.```bash
# Create docker instance based on docker-compose.yml
docker compose up
```8. Make sure terminal have the following prompt below continue:
![Fiber cli prompt](./image/fiber-cli.png)
9. Open Postman and start to send RESTful API with correct parameter as stated in API sesison below.
---
## API Endpoints Reference
> `GET` http://localhost:3000
This API will return the raw JSON format of stored object(s) in Postgres. Hence, it will be empty by default and objects will be displayed after running `POST` request for at least once and success.
Sample Response
```json
[
{
"ID": 1,
"CreatedAt": "2022-12-14T14:42:59.162640885Z",
"UpdatedAt": "2022-12-14T14:42:59.162640885Z",
"DeletedAt": null,
"question": "Is this a sample?",
"answer": "Yes"
},
{
"ID": 2,
"CreatedAt": "2022-12-14T14:45:11.451989Z",
"UpdatedAt": "2022-12-14T14:45:11.451989Z",
"DeletedAt": null,
"question": "Is this a sample too?",
"answer": "Yea!"
}
]
```---
> `POST` http://localhost:3000/fact
Use `Postman` and create a new POST request.
Then, choose `Body` , then `raw` and make sure JSON is selected. Paste in the following skeleton and fill in accordingly.
Body
| name | required |
| -------- | -------- |
| question | `yes` |
| answer | `yes` |Sample Body
```JSON
{
"question": "Who learn Golang today?",
"answer": "Me!",
}
```Response
```json
{
"ID": 1,
"CreatedAt": "2022-12-14T14:42:59.162640885Z",
"UpdatedAt": "2022-12-14T14:42:59.162640885Z",
"DeletedAt": null,
"question": "Who learn Golang today?",
"answer": "Me!"
}
```---
## Third-party Golang package/modules installed
- Go-fiber
- Gorm with Postgres driver
- Air