Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Ananto30/gmocker

Create a blazing fast mock server with just a JSON file
https://github.com/Ananto30/gmocker

fasthttp go golang mock-server

Last synced: 12 days ago
JSON representation

Create a blazing fast mock server with just a JSON file

Awesome Lists containing this project

README

        

# Gmocker
[![codecov](https://codecov.io/gh/Ananto30/gmocker/branch/main/graph/badge.svg?token=ulDcbeJyak)](https://codecov.io/gh/Ananto30/gmocker)
[![Maintainability](https://api.codeclimate.com/v1/badges/8d035908151fad8489ee/maintainability)](https://codeclimate.com/github/Ananto30/mocker/maintainability)
[![Go Report Card](https://goreportcard.com/badge/github.com/Ananto30/mocker)](https://goreportcard.com/report/github.com/Ananto30/mocker)

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](https://github.com/Ananto30/mocker#sample-mockjson-file).

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

## Run
With defaults -
```bash
./mocker
```
**Defaults: `addr=localhost:7070` , `file=mock.json`**

With custom flags -
```bash
./mocker -addr -file
```

For windows -
```powershell
mocker.exe -addr -file
```

## Sample mock.json file
```
{
"": {
"statusCode": ,
"responseBody": {
...
}
}
}
```
These `path`s will be matched and the json will be sent.

Example -
```json
{
"/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 -
```bash
go mod download
go build
```

For windows -
```bash
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= GOARCH= go build`