status-echo-server

command
v0.1.0-f80a32d Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

README

Status Echo Server

A simple Go HTTP server that echoes back a configured or requested HTTP status code.

Behavior

The server listens on a configured port and handles all HTTP requests by returning a text response with the requested HTTP status code.

The status code returned is determined in the following order of precedence:

  1. URL Path Suffix: If the path ends with /status/<3-digit-code> (e.g., /status/201), that code is used.
  2. Query Parameter: If no valid path suffix is found, it looks for the status query parameter (e.g., /?status=202).
  3. Default Flag: If neither is provided, it defaults to the value set by the -http_status CLI flag (which defaults to 200).
Validation

If a status code is requested via path or query but is invalid (e.g., not a number, or not a recognized HTTP status code like 999), the server logs a warning and returns 400 Bad Request.


Running Locally

To build and run the server locally using Bazel:

bazel run //src/go/cmd/status-echo-server:status-echo-server-app -- -port 8080

Running Tests

To run the unit tests locally using Bazel:

bazel test :go_default_test
Useful Test Flags
  • Disable caching (force tests to run even if code didn't change):
    bazel test :go_default_test --nocache_test_results
    
  • Show verbose output (print test logs to terminal even if they pass):
    bazel test :go_default_test --test_output=all
    
  • Run a specific test:
    bazel test :go_default_test --test_arg=-test.run=TestEchoHandler/OK_status_on_root_path
    

Running Benchmarks

To run the Go micro-benchmarks locally using Bazel:

bazel test :go_default_test --test_arg=-test.bench=. --test_arg=-test.run=^$ --test_output=all --test_arg=-test.benchmem 
Useful Benchmark Flags
  • Disable caching (force benchmarks to run):
    bazel test :go_default_test --nocache_test_results --test_output=all --test_arg=-test.bench=. --test_arg=-test.run=^$ --test_arg=-test.benchmem 
    
  • Run for a specific duration (default is 1s):
    bazel test :go_default_test --test_arg=-test.benchtime=5s --test_arg=-test.bench=. --test_arg=-test.run=^$ --test_output=all --test_arg=-test.benchmem 
    

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