mocker

command module
v0.0.0-...-142e9c8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 9 Imported by: 0

README

Gmocker

codecov Maintainability Go Report Card

Run a blazing fast mock server in just seconds! 🚀

All you need is to make a json file that contains path and response mapping. See an example here.

Only json is supported for now, please create issues for bugs and new features.

Run

With defaults -

./mocker

Defaults: addr=localhost:7070 , file=mock.json

With custom flags -

./mocker -addr <YOUR_HOST_AND_PORT> -file <MOCK_JSON_FILE_LOCATION>

For windows -

mocker.exe -addr <YOUR_HOST_AND_PORT> -file <MOCK_JSON_FILE_LOCATION>

Sample mock.json file

{
  "<YOUR_PATH>": {
    "statusCode": <INTEGER>,
    "responseBody": {
      <YOUR_RESPONSE_BODY> ...
    }
  }
}

These paths will be matched and the json will be sent.

Example -

{
  "/hello/worlds": {
    "statusCode": 200,
    "responseBody": {
      "message": "Hello worlds!",
      "data" : {
        "time": "now"
      },
      "worlds": [
        "cross origin world",
        "mars world",
        "moon world"
      ]
    }
  }
}

If a request lands in the server in path /hello/worlds the json object inside responseBody will be sent as response.

The request type [POST or GET] doesn't matter.

Build

For mac/linux -

go mod download
go build

For windows -

go mod download
GOOS=windows GOARCH=amd64 go build 

**If the build/binary doesn't work for you, you can do this -

  • Check your os and arch using this command - go env GOOS GOARCH
  • Use the output os and arch to build the binary - GOOS=<YOUR_OS> GOARCH=<YOUR_ARCH> go build

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