animal-facts

module
v0.0.0-...-774d41c Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT

README

animal-facts

Simple API to spread random animal facts to everyone. Animals are awesome, everyone should know this.

Usage of public api

The public api is built get facts without authentication for public usage.

Detailed information about the available endpoints can be seen on the swagger page.

# get random fact
curl https://animal-facts.cafo.dev/api/v1/facts
# example response
{"id":"6578bf140e487ecc049c7594","fact":"The Blue Whale is the largest animal that has ever lived.","source":"https://factanimal.com/blue-whale/"}

# get fact by id
curl https://animal-facts.cafo.dev/api/v1/facts/6578bf140e487ecc049c7594
# example response
{"id":"6578bf140e487ecc049c7594","fact":"The Blue Whale is the largest animal that has ever lived.","source":"https://factanimal.com/blue-whale/"}

Usage of internal api

The internal api is built to manage the facts database. A management UI using the API is built here. To get access to be able to manage the public's api database of https://animal-facts.cafo.dev/, feel free to create an issue at this or the animal-facts-manager repository.

Development with own database

Prerequisites:

  • go:
    • version 1.22
  • mongo database:
    • database named "animal-facts" with collection named "facts" (database name can be overwritten with environment variable MONGODB_DATABASE_NAME)
  • copy the .env.dist file to .env and fill the variables for the mongodb connection to your database
# run the public api locally
make public-api-run

# run the internal api locally
make internal-api-run

# build the public api locally
make public-api-build

# build the internal api locally
make internal-api-build

# generate swagger docs for the public api locally
make public-api-generate-swagger

# generate swagger docs for the internal api locally
make internal-api-generate-swagger

Versioning of the APIs

The internal and public api always have the same version. To update the version simply run the following command and commit and push your changes. The release and tag for the repo will be created in the GitHub action run.

make release-version VERSION=1.2.12

Directories

Path Synopsis
api module
cmd
internal-api
api
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
pkg
log
public-api
api
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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