shakespeare-go

module
v0.0.0-...-ff919dc Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT

README

shakespeare-go

Based on the project Shakespeare Quotes which is written using Node on the server-side.

This repo will re-build that project with Golang on the server-side. Currently hosted on https://render.com/

Setup Local Environment

Requirements:

  • golang 1.19.0 if not using docker
  • Docker and Docker Compose
  • make (to run the commands in the Makefile)

Copy the .env.example to .env and set the correct values

Docker Commands to build the container to work in:

  • make docker-up : build image and run the container
  • make docker-down : stop the container
  • make docker-prune : prune images and containers
  • make docker-exec : execute the container (run make docker-up before this)

Once inside the container or if running locally without docker:

  • make fmt : format the code
  • go run ./cmd/main.go : run the code
  • go mod tidy : remove unused packages
  • make toLinux : build the application
  • ./shakespeare : run the application/server

Generate Swagger Docs:

  • make swagger : generates the swagger docs
  • make swagger-fmt : formats the swagger docs

Linting:

  • make lint : lints the project using golangci-lint

Running the Application

Without docker

To run locally without docker

go run cmd/main.go
With docker

Build final application in docker and run:

  • make build-app: build the final application in the container
  • make run-app : run the application/server in the container
  • make stop-app : stop the container
  • make start-app : start the stopped container
  • make remove-app : remove the stopped container
Interacting with the API

With the application running, use postman to send GET requests to retrieve an individual quote or all quotes (limited to 10 per page)

# retrieve first 10 quotes in created_date desc order
http://localhost:5000/api/v1/quotes

# retrieve from page 5
http://localhost:5000/api/v1/quotes/5

# retrieve individual quote
http://localhost:5000/api/v1/quote/5abcd0271b46e00014abef3c # where `5abcd0271b46e00014abef3c` is an id of a quote.

Swagger

Interact using swagger at http://localhost:5000/swagger/index.html

Directories

Path Synopsis
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
internal

Jump to

Keyboard shortcuts

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