Skip to content

A module and CLI application to make mock servers in a ease.

License

Notifications You must be signed in to change notification settings

aka-l24n/mockgopher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Luis Medina
Nov 6, 2022
9f4e9f9 · Nov 6, 2022

History

44 Commits
Apr 10, 2020
Nov 6, 2022
Mar 8, 2020
Jan 27, 2022
Mar 4, 2020
Apr 10, 2020
Nov 6, 2022
Mar 11, 2020
Mar 4, 2020
Mar 5, 2020
Oct 21, 2022
Oct 21, 2022
Mar 11, 2020
Mar 6, 2020
Mar 11, 2020

Repository files navigation

MockGopher

Is a library and CLI application to make mock server in a ease.

CLI Instalation

To actually use MockGopher you need to install Go first, you can find how to install it in https://golang.org/. Then you can run the go get command.

go get -u github.com/medinam/mockgopher/cli/mockgopher

Now you can use MockGopher normally, see the instructions below.

CLI Usage

You can see some examples in cli/examples folder.

Project Structure

.
├── resources            # Files that can be served
├── templates            # All templates go here
└── project.toml         # Configuration file, see "The TOML file"

The TOML File

host = "0.0.0.0"
port = 3000

[[routes]]
  [routes.request]
    path = "/posts"
    method = "GET"
    headers = [
      { key = "Content-Type", value = "application/json.*" }
    ]
  [routes.response]
    headers = [
      { key = "Content-Type", value = "application/json" }
    ]
    template = "get-posts.json"

[[routes]]
  [routes.request]
    path = "/media/avatar/{file}"
    method = "GET"
  [routes.response]
    headers = [
      { key = "Content-Type", value = "image/svg+xml" }
    ]
    template = "get-posts.json"
    resources = [
      "avatars/25789.svg",
      "avatars/527688.svg",
      "avatars/7896451.svg",
      "avatars/9785412.svg",
      "avatars/25678412.svg"
    ]

Serve

mockgopher.exe .\path\to\project.toml

Work in Progress

Right now this application is completely functional, but there are some stuff to improve:

  • Create more advanced examples
  • Refactor core code
  • Improve CLI error handling
  • Implement optional cache to return same response in every call