http_helloworld

command module
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 16 Imported by: 0

README

http_helloworld

Minimal HTTP server for testing purposes on docker

CodeQL CI Go

This server exposes only a root endpoint, with a JSON response like above:

{
  "ip": "172.19.0.1:45370",
  "runningTime": "10.563721891s",
  "startTime": "2022-03-12 11:47:57.966620544 +0000 UTC m=+0.000435499",
  "time": "2022-03-12 11:48:08.530328605 +0000 UTC m=+10.564143553",
  "requestCount": 3,
  "tag": "testing"
}

Usage

docker run --rm -p 8080:8080 guionardo/http_helloworld:latest

This server will listen to HTTP port 8080, but you can change this behavior using a environenment variable PORT.

docker run --rm p 8081:8081 -e PORT=8081 -e TAG=testing guionardo/http_helloworld:latest

You can use the environment vars:

  • PORT = Por number (between 1 and 65535)
  • TAG = Text for add into JSON response, use for show any custom data

Custom endpoints

You can add your customized static endpoints using a configuration file like this:

In folder ./custom_responses add a routes.json file with an array of objects:

Field type Description
path string URL path
source_file string name of file with content, without path
method string HTTP method (default = GET)
status_code integer HTTP status code (default = 200)
content_type string Content-Type header (default = detected from source file)

Example:

[
    {
        "path": "/api",
        "source_file": "api.content",
        "method": "GET",
        "status_code": 200,
        "content_type": "application/json",
    },
    {
      "path":"/test",
      "source_file": "test.content",
      "method": "POST",
      "status_code": 202
    }
]

And add the files api.content and test.content to ./custom_responses folder with some content.

When the server receives a /api request, it will response the body of api.content file. And so on to /test : test.content

You need to change the docker command to this:

docker run --rm -p 8080:8080 -e PORT=8080 \
  -v ${PWD}/custom_responses:/app/custom_responses \
  guionardo/http_helloworld:latest

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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