golang-mongodb-rest

command module
v0.0.0-...-23e23d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 8 Imported by: 0

README

GoLang + MongoDB RESTFul

Go Report Card

This project is a 'Boilerplate' or 'Starter' to build RESTful Applications and microservices using GoLang (Gin HTTP web framework), MongoDB.

Table of Contents

Features

Prerequisites

If you are not using Docker, you should also have:

  • MongoDB

Getting Started

Repository Clone
# Clone Project
git clone https://github.com/janrockdev/golang-mongodb-rest.git go-rest

# Change Directory
cd go-rest
Using Docker
# Build & Create Docker Containers
docker-compose up -d
Using Local Environment
# Copy Example Env file
cp ./env.example .env

# Change MongoDB URI and Database Name

# MONGO_URI=<mongo_uri>
# MONGO_DATABASE=<db_name>

# Download Modules
go mod download

# Build Project
go build -o go-starter .

# Run the Project
./go-starter

The application starts at port 8080:

  • GET /v1/ping Health check endpoint, returns 'pong' message

  • POST /v1/auth/register Creates a user and tokens
  • POST /v1/auth/refresh Refresh expired tokens
  • POST /v1/auth/login Login a user

  • POST /v1/notes Create a new note
  • GET /v1/notes Get paginated list of notes
  • GET /v1/notes/:id Get a one note details
  • PUT /v1/notes/:id Update a note
  • DELETE /v1/notes/:id Delete a note

  • GET /swagger/* Auto created swagger endpoint

You can also see: http://localhost:8080/swagger/index.html

If you want to add new routes and swagger docs, you should run swag init See: Gin Swagger

Project Structure

├── controllers         # contains api functions and main business logic
├── docs                # swagger files 
├── logs
├── middlewares         # request/response middlewares
│   └── validators      # data/request validators
├── models              
│   └── db              # collection models
├── routes              # router initialization
└── services            # general service & database actions

Future Work

  • Rate Limiting
  • Testing

License

MIT License - Jan Rock

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL