Skip to content

imposter-project/imposter-go

Repository files navigation

imposter-go CI

A Go implementation of the Imposter Mock Engine. This project is now considered stable.

Features

⚠️ Limitations

Getting Started

The recommended way to get started for most users is to use the latest Imposter CLI.

Note If you don't have Imposter CLI installed, or you want to use the imposter-go binary directly, continue to the Installation section.

With Imposter CLI installed, use the -t golang option, and pass -v <version>:

imposter up -t golang -v <version>

...where version is from the Releases page, for example:

imposter up -t golang -v 0.15.0

Installation

Using Pre-built Binaries

Download the latest release for your platform from GitHub:

macOS

# For Intel Macs (amd64)
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_darwin_amd64.tar.gz | tar xz
sudo mv imposter-go /usr/local/bin/

# For Apple Silicon Macs (arm64)
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_darwin_arm64.tar.gz | tar xz
sudo mv imposter-go /usr/local/bin/

Linux

# For amd64 systems
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_linux_amd64.tar.gz | tar xz
sudo mv imposter-go /usr/local/bin/

# For arm64 systems
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_linux_arm64.tar.gz | tar xz
sudo mv imposter-go /usr/local/bin/

Windows

  1. Download the latest release from GitHub Releases
  2. Extract the imposter-go_windows_amd64.zip file
  3. Add the extracted imposter-go.exe to your PATH or move it to a directory in your PATH

Using Docker

Docker images are available on Docker Hub.

There are two image variants:

Variant Image Description
Core outofcoffee/imposter Minimal image with core functionality
All outofcoffee/imposter-all Includes all plugins

Each image is published with the following tags:

  • 5-beta - latest beta release (major version)
  • <version>-beta - specific version, e.g. 5.14.3-beta

Quick start

docker run --rm -p 8080:8080 \
  -v /path/to/config:/opt/imposter/config \
  outofcoffee/imposter:5-beta

Pin to a specific version

docker run --rm -p 8080:8080 \
  -v /path/to/config:/opt/imposter/config \
  outofcoffee/imposter:5.14.3-beta

To use the all-in-one image (with all plugins):

docker run --rm -p 8080:8080 \
  -v /path/to/config:/opt/imposter/config \
  outofcoffee/imposter-all:5-beta

Usage

Run with a directory containing Imposter configuration file(s):

imposter-go ./examples/rest/simple

Visit http://localhost:8080/hello in your browser or use curl:

curl http://localhost:8080/hello

Examples

The repository includes several examples demonstrating different features:


Configuration

A subset of the Imposter environment variables are supported. For example:

Set the IMPOSTER_PORT environment variable to change the default port:

export IMPOSTER_PORT=9090  # Default: 8080

Enable recursive directory scanning for configuration files:

export IMPOSTER_CONFIG_SCAN_RECURSIVE=true  # Default: false

Set the IMPOSTER_SERVER_URL environment variable to override the URL reported by the server:

export IMPOSTER_SERVER_URL=http://example.com  # Default: http://localhost:8080

Set the IMPOSTER_LOG_LEVEL environment variable to control logging verbosity:

export IMPOSTER_LOG_LEVEL=DEBUG  # Available levels: TRACE, DEBUG, INFO, WARN, ERROR

The default log level is DEBUG. Available log levels:

  • TRACE - Most verbose, logs all messages
  • DEBUG - Detailed information for debugging
  • INFO - General operational messages
  • WARN - Warning messages for potentially harmful situations
  • ERROR - Error messages for serious problems

TLS and HTTP/2

By default Imposter serves HTTP/2. Without TLS the server runs with h2c (HTTP/2 cleartext), which also remains compatible with HTTP/1.1 clients.

To enable TLS (h2 — HTTP/2 over TLS), set both of:

export IMPOSTER_TLS_CERT_FILE=/path/to/server.crt
export IMPOSTER_TLS_KEY_FILE=/path/to/server.key

Both variables must be set; setting only one is ignored with a warning. When TLS is enabled, the default IMPOSTER_SERVER_URL scheme becomes https.

HTTP/2 can be disabled (serving HTTP/1.1 only) by setting IMPOSTER_HTTP2_ENABLED=false. This applies to both cleartext and TLS modes.

Legacy Configuration Support

Imposter Go supports legacy configuration formats, for backwards compatibility with older Imposter configurations.

Enable support for legacy configuration format:

export IMPOSTER_SUPPORT_LEGACY_CONFIG=true

When legacy configuration support is enabled, older configuration formats are automatically transformed. For example:

# Legacy format (root-level fields)
plugin: rest
path: /hello
contentType: text/plain
response:
  staticData: Hello, World!
# Legacy format (deprecated names for resource-level fields)
plugin: rest
resources:
  - path: /hello
    contentType: application/json
    response:
      staticFile: response.json # Deprecated, use file instead
      staticData: Hello, World! # Deprecated, use content instead
      scriptFile: transform.js  # Deprecated, use a script step instead

Development

See the Development Guide for instructions on building, testing, and contributing to the project.

About

A Go implementation of the Imposter Mock Engine.

Resources

Stars

Watchers

Forks

Contributors

Languages