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

github.com/freshusername/news-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/freshusername/news-api

  • v0.0.0-20240215101823-8a9a52226d30
  • Source
  • Go
  • Socket score

Version published
Created
Source

news-api

News CRUD microservice written in Golang

Requirements for the task:

  • Write a Golang microservice for CRUD operations with news.

Approximate structure of the API:

  • POST /posts

  • GET /posts

  • PUT /posts/{id}

  • GET /posts/{id}

  • DELETE /posts/{id}

  • Post minimum contains: id, title, content, created_at, updated_at.

  • Tests are required. (using testcontainers-go for spinning postgres docker containers)

It will be an advantage:

  • Use PostgreSQL
  • Makefile
  • Data validation (using reflection)
  • Migration (using Goose)
  • OpenAPI specification (using go-swagger)
  • REST microservice

Upload the code to Github.

There should be startup instructions. Ideally, this is a Makefile for assembly and a docker-compose file that should raise the DB instance

The following will be assessed:

  • Organization of the API
  • Tests (successful and failed cases)

Tech stack

  • Postgres for DB
  • Docker compose for local development
  • Air for hot reload

How to run

  1. You should create .env.local in root folder and paste these secrets:
DB_USER=postgres
DB_PASSWORD=admin
DB_NAME=news
DB_PORT=5432
DB_HOST=db #changed during deployment, from docker-compose if local development

POSTGRES_USER=postgres
POSTGRES_PASSWORD=admin
POSTGRES_DB=news
  1. Run make docker-up to start api and db locally
  2. Apply Goose migration:
    • Install Goose locally
    • Run migration with your connection string (instructions here)
    • export GOOSE_DRIVER=postgres
    • export GOOSE_DBSTRING=postgresql://postgres:admin@127.0.0.1:5432/news?sslmode=disable
    • make migrate-up
  3. Once you have up and running both your containers: docker containers You can start making requests to app on port 3000. See postman collection attached in /postman folder.
  4. Swagger OPENAPI specification is available at GET http://localhost:3000/swagger

FAQs

Package last updated on 15 Feb 2024

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