This is the backend of a polling app written purely in Go.
-
/- Method: GET
- Response:
{ "message": "welcome to the go auth app" }
-
/ping- Method: GET
- Response:
{ "message": "server is up and running" }
-
/v1/auth/register- Method: POST
- Request Body:
{ "username": "your_username","email": "your_email", "password": "your_password", "confirmpassword": "your_password" } - Response:
{ "message": "user successfully created" }
-
/v1/auth/login- Method: POST
- Request Body:
{ "username": "your_username", "password": "your_password" } - Response:
{ "message": "Login successful", "token": "your_jwt_token" }
-
/v1/polls- Method: POST
- Request Body:
{ "title": "poll_title", "description": "poll_description", "options": [{"text": "option1"}, {"text": "option2"}] } - Response:
{ "poll_id": poll_id, "message": "Poll created successfully" }
-
/v1/polls- Method: GET
- Response:
[ { "poll_id": poll_id, "title": "poll_title", "description": "poll_description", "created_at": "timestamp" } ]
-
/v1/polls/{poll_id}- Method: GET
- Response:
{ "poll_id": poll_id, "title": "poll_title", "description": "poll_description", "options": [{"option_id": option_id, "text": "option_text", "number_of_votes": vote_count}], "created_at": "timestamp" }
-
/v1/polls/{poll_id}/vote- Method: POST
- Request Body:
{ "option_id": option_id } - Response:
{ "message": "Vote cast successfully" }
- Chi for routing
- JWT for token generation
- PostgreSQL for database
- Migrate (for DB migrations)
- Air: Optional (For live reload during development. It can be installed with
go install github.com/air-verse/air@latest)
SERVER_PORT: Port on which the server runs (default: 8000)POSTGRES_SERVER: PostgreSQL server address (default: localhost)POSTGRES_PORT: PostgreSQL server port (default: 5432)POSTGRES_DB: PostgreSQL database name (default: go_app)POSTGRES_USER: PostgreSQL database user (default: sensei)POSTGRES_PASSWORD: PostgreSQL database password (default: 12345)JWT_EXP: JWT token expirationJWT_SECRET: JWT secret key
-
Clone the repository:
git clone https://github.com/xtasysensei/go-poll.git cd go-poll -
Setup a PostgreSQL database based on the credentials in the
.envfile. -
Install
makeand run:make migrate up
-
For complete functionality, use
makeandair, for live reload during development, then run:make run #or make run-air
A docker image is available at dockerhub via go-poll.
Prerequisites: Docker and Docker Compose.
- If you are using Docker Desktop, both of these should be already installed.
- If you prefer Docker Engine on Linux, make sure to follow their installation guide.
We provide support for the latest Docker release as shown above. If you are using Linux and the Docker package that came with your package manager, it will probably work too, but support will only be best-effort.
Upgrading Docker from the package manager version to upstream requires that you uninstall the old versions as seen in their manuals for Ubuntu, Fedora and others.
Then, to get started:
-
Run
docker versionanddocker compose versionto see if you have Docker and Docker Compose properly installed. You should be able to see their versions in the output.For example:
>>> docker version Client: [...] Version: 23.0.5 [...] Server: Docker Desktop 4.19.0 (106363) Engine: [...] Version: 23.0.5 [...] >>> docker compose version Docker Compose version v2.17.3If you don't see anything or get a command not found error, follow the prerequisites to setup Docker and Docker Compose.
-
Clone or download this repository and extract,
-
Open a terminal of your choice and change its working directory into this folder (
go-polll). -
Run
docker compose up -d.
go-polll is now available at http://localhost:9000.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.