gomongowebapi

module
v0.0.0-...-4db4453 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: Apache-2.0

README

Go Clean Architecture

Example that shows core principles of the Clean Architecture in Golang projects.

Project Description&Structure:

REST API with custom JWT-based authentication system.

Structure:

4 Domain layers:

  • Models layer
  • Repository layer
  • UseCase layer
  • Delivery layer

API:

POST /auth/sign-up

Creates new user

Example Input:
{
	"username": "andrii",
	"password": "password"
} 
POST /auth/sign-in

Request to get JWT Token based on user credentials

Example Input:
{
	"username": "andrii",
	"password": "password"
} 
Example Response:
{
	"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NzEwMzgyMjQuNzQ0MzI0MiwidXNlciI6eyJJRCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCIsIlVzZXJuYW1lIjoiemhhc2hrZXZ5Y2giLCJQYXNzd29yZCI6IjQyODYwMTc5ZmFiMTQ2YzZiZDAyNjlkMDViZTM0ZWNmYmY5Zjk3YjUifX0.3dsyKJQ-HZJxdvBMui0Mzgw6yb6If9aB8imGhxMOjsk"
} 
POST /api/bookmarks

Creates new bookmark

Example Input:
{
	"url": "https://github.com/andtkach",
	"title": "Go Clean Architecture example"
} 
GET /api/bookmarks

Returns all user bookmarks

Example Response:
{
	"bookmarks": [
            {
                "id": "5da2d8aae9b63715ddfae856",
                "url": "https://github.com/andtkach/gomongowebapi",
                "title": "Go Clean Architecture example"
            }
    ]
} 
GET /api/bookmarks/:id

Returns one bookmark

Example Response:
{
	"bookmark":
			{
                "id": "5da2d8aae9b63715ddfae856",
                "url": "https://github.com/andtkach/gomongowebapi",
                "title": "Go Clean Architecture example"
            }
} 
PUT /api/bookmarks

Updates bookmark

Example Input:
{
	"id": "5da2d8aae9b63715ddfae856",
	"url": "https://github.com/andtkach",
	"title": "Go Clean Architecture example"
} 
DELETE /api/bookmarks

Deletes bookmark by ID:

Example Input:
{
	"id": "5da2d8aae9b63715ddfae856"
} 

Requirements

  • go 1.20
  • docker & docker-compose

Run Project

Use make run to build and run docker containers with application itself and mongodb instance

go mod tidy

make build

make runlocal make publish

docker run -p 80:80 andreytkach/go-mongo-webapi docker push andreytkach/go-mongo-webapi

Jump to

Keyboard shortcuts

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