Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/arkosh744/simplerest_blog

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/arkosh744/simplerest_blog

  • v0.0.0-20221030183330-6e040850fa0a
  • Source
  • Go
  • Socket score

Version published
Created
Source

Simple REST API for Note-taking App with auth

Gopher This is Golang REST API server example including the following features:
  • based on Go web framework - Gin (firstly write on go http)
  • made with Clean Architecture in mind
  • have services that work with PostgreSQL database
  • includes controller go tests based on mocks auto-generated with go:generate and mockery
  • Postman commands included aswell
  • config based on env file with viper

To run app

Setup your local app.env @ ./configs/app.env file and then run:

make run

or

docker compose --env-file .\configs\app.env up --build post-app

To run with gRPC audit logger please run with grpc server @ https://github.com/Arkosh744/grpc-audit-log


TESTs

To run tests:

make test
#or
go test -v -count=1 ./...

REST API:

Examples of usage

First we need to sign-up:

POST /auth/sign-up

{
  "name": "NewGopher",
  "email": "go@golang.com",
  "password": "gog8g!pher"
}

response: "OK"


Then we need to sign-in:

POST /auth/sign-in

{
  "email": "go2g2o2@golang.com",
  "password": "aaaaaa"
}

response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjYyNzc4MjcsImlhdCI6MTY2NjE5MTQyNywic3ViIjoiMSJ9.WZeSW-tLPQZBXfhsTza_JLXKR9O2CGAgRh32uNzG1Tg"
}

Then we can create a post:

First, we need add authorization token in headers: Authorization: Bearer <token>

Then we can create a post: POST /post

{
  "title": "web-develompent",
  "body": "THis is my first REST API in GO lang"
}

To get all posts: GET /post

[
  {
    "id": 1,
    "title": "web-develompent",
    "body": "THis is my first REST API in GO lang",
    "AuthorId": 1,
    "created_at": "2022-10-12T15:21:56.075473Z",
    "updated_at": "2022-10-12T15:21:56.075473Z"
  },
  {
    "id": 3,
    "title": "web-develompent 3",
    "body": "Slice in Go lang",
    "AuthorId": 1,
    "createdAt": "2022-10-12T15:25:31.069819Z",
    "updatedAt": "2022-10-12T15:25:31.069819Z"
  }
]

To get post by id: GET /post/<id>

  {
    "id": 1,
    "title": "web-develompent",
    "body": "THis is my first REST API in GO lang",
    "AuthorId": 1,
    "created_at": "2022-10-12T15:21:56.075473Z",
    "updated_at": "2022-10-12T15:21:56.075473Z"
  }

To update post by id: PUT /post

[
  {
    "id": 1,
    "title": "web-develompent UPDATED",
    "body": "THIS IS PYTHON"
  }
]

response:

  {
    "message": "updated"
  }

Swagger docs

to update need to run command: swag init -g cmd/main.go

Example of usage: http://localhost:8080/swagger/index.html img.png

FAQs

Package last updated on 30 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc