Skip to content

The underlying image generation service behind placeholder.app. Built with Go and Gin.

License

Notifications You must be signed in to change notification settings

placeholder-app/backend

Repository files navigation

Introduction

This is the backend API behind placeholder.app. See the frontend repository here

Go Tests Go Report Card Dependency Review

Examples

Sizes supported are 30px thru 4000px. These are just example sizes with default options.

Image Examples

img

img

img

img

img

img

img

img

img

Usage

Setup

git clone https://github.com/placeholder-app/backend
cd backend/
go install

Building

To build all binaries from the source

make build

To build a specific binary

make build_[platform]

Platforms: linux, mac, freebsd, windows

All of the above commands output to the /bin folder by default. To run the application, simply execute the build

./bin/[platform]

To clean the workspace

make clean

Running Directly

If you choose to run without compiling, you can refer to this section.

Run with default options (For local testing)

go run main.go

Run with configuration (See main.go for options)

PORT=80 go run main.go

Run with SSL

SSLCERT=./cert.pem SSLKEY=./key.pem PORT=443 go run main.go

Note: On Linux, you may need to run go as sudo for ports 80 or 443

Testing & Documentation

Testing

The included makefile provides options to run golang test cases, and to build the openapi documentation.

To run the included Golang unit tests, with coverage,

make tests

Note: This will not output any files. See the commandline output

Building OpenAPI Docs

The OpenAPI (swagger) file is in .vscode/openapi.yml.

To build the HTML documentation file (found on docs.placeholder.app), see below.

make docs

Alternatively, you can run the command directly

openapi-generator-cli generate --skip-validate-spec -i ./.vscode/openapi.yml -g html2 -o ./docs

Both of the above commands output the HTML documentation inside ./docs

HTTP Request Simulation

If you use VisualStudio Code, the ThunderClient request repository is available in .vscode/thunder-tests.

You can simulate requests to the API, or run HTTP-based testing.

Requirements & Dependencies

  • Go 1.19 (Minimum)
  • gin-gonic/gin
  • openapi-generator-cli (For documentation only)

Credits

Loosely built from ninjawerk/go-rest-boilerplate.