Skip to content

barbarbar338/go-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-api

This api is a security-focused system that combines role-based authentication, streamlined CRUD operations (Create, Read, Update, Delete), and efficient user management. It empowers administrators to control access based on user roles while providing a seamless experience for data manipulation and user interactions.

Architecture Overview

├───cmd
├───docker
└───pkg
    ├───auth
    ├───db
    ├───entities
    ├───errors
    └───server

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

PORT, DB_URI, DB_NAME, JWT_SECRET

Run Locally

Make sure Docker, Git and Go is installed.

Clone the project

  git clone https://github.com/Merloss/go-api.git

Go to the project directory

  cd go-api

Run services

  docker-compose -f /docker/docker-compose.yml up -d

Install dependencies

  go mod tidy

Start the server

  go run .\cmd\main.go

API Reference

Register

  POST /api/auth/register
Field name Type Description
username string Required. Your username
password string Required. Your password

Login

  POST /api/auth/login
Field name Type Description
username string Required. Your username
password string Required. Your password

Get all posts

  GET /api/posts

Create post (editor only)

  POST /api/posts
Field name Type Description
title string Required. Post title
description string Required. Post description

Edit post (editor only)

  POST /api/posts/:id
Field name Type Description
title string Required. Post title
description string Required. Post description
status string Admin only Post status

Delete post (admin only)

  DELETE /api/posts/:id
Parameter Type Description
id string Required. Post ID

Get pending posts (admin only)

  GET /api/posts/pending

Edit user (admin only)

  POST /api/users/:id/edit
Field name Type Description
username string User username
roles string[] User roles

Running Tests

To run tests, run the following command

  go test ./...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

  • Go 100.0%