mockgopher

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

MockGopher

Is a library and CLI/GUI 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

GUI Usage

The GUI of MockGopher is actually under development, you can see updates here or follow me @luismedina_git on Twitter.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func View

func View(template string) (string, error)

Types

type Blueprint

type Blueprint struct {
	Host            string
	Port            int
	Delay           *int64
	Routes          []*Route
	Log             io.Writer
	ResourceLocator ResourceLocator
}

Blueprint represent how should be serve the routes

func NewBlueprint

func NewBlueprint(host string, port int) *Blueprint

NewBlueprint creates a new instance with some default values

func (*Blueprint) AddRoute

func (b *Blueprint) AddRoute(path string, method string, body string) *Route

AddRoute is a simple way to add new routes to a created blueprint

func (*Blueprint) MakeRouter

func (b *Blueprint) MakeRouter() *mux.Router

MakeRouter create a router using the blueprint routes

type Faker

type Faker struct {
	Address     faker.FakeAddress
	App         faker.FakeApp
	Avatar      faker.FakeAvatar
	Bitcoin     faker.FakeBitcoin
	Business    faker.FakeBusiness
	Code        faker.FakeCode
	Commerce    faker.FakeCommerce
	Company     faker.FakeCompany
	Date        faker.FakeDate
	Finance     faker.FakeFinance
	Hacker      faker.FakeHacker
	Internet    faker.FakeInternet
	Lorem       faker.FakeLorem
	Name        faker.FakeName
	Number      faker.FakeNumber
	PhoneNumber faker.FakePhoneNumber
	Team        faker.FakeTeam
	Time        faker.FakeTime
}

Faker it's just a struct thats wraps faker packages interfaces

func NewFaker

func NewFaker() *Faker

NewFaker creates a Faker intance using the original library implementation

type Header struct {
	Key   string
	Value string
}

type Request

type Request struct {
	Path    string
	Methods []string
	Headers []*Header
}

type ResourceLocator

type ResourceLocator interface {
	Locate(identifier string) []byte
}

type Response

type Response struct {
	Template  string
	Status    uint16
	Resources []string
	Delay     *int64
	Headers   []*Header
}

type Route

type Route struct {
	Request  *Request
	Response *Response
}

type Stdout

type Stdout struct {
	// contains filtered or unexported fields
}

Stdout is used to print stuff in the standar output implementing io.Writer

func NewStdout

func NewStdout() *Stdout

NewStdout return a Stdout object thats use the standar output

func (*Stdout) Write

func (s *Stdout) Write(p []byte) (n int, err error)

Write to standar output as string

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL