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

  • No support for Groovy scripting
  • No support (yet) for some SOAP styles (#7)

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 (x86_64)
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_Darwin_x86_64.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 x86_64 systems
curl -L https://github.com/imposter-project/imposter-go/releases/latest/download/imposter-go_Linux_x86_64.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_x86_64.zip file
  3. Add the extracted imposter-go.exe to your PATH or move it to a directory in your PATH

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

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 2

  •  
  •  

Languages