gomock

package module
v0.0.0-...-c662eb3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 5 Imported by: 0

README

Go http mock server

Mock your APIs in a really fast, robust and comprehensive way

Install

go get github.com/jaschweder/go-http-mock-server

Getting start

Create a mock.json file like this:

{
    "server":{
        "address":"0.0.0.0",
        "port":8080
    },
    "routes":[
        {
            "request":{
                "method":"GET",
                "url":"/hello"
            },
            "response":{
                "status":200,
                "body":"{\"message\": \"World!\"}"
            }
        }
    ]
}

Run gomock:

$ gomock mock.json

Try make a request:

$ curl http://localhost:8080/hello
{message: "World!"}

That's it! You rock!!!

How to contribute:

Issue report and PR's are welcome

Author:

Created by Jonathan A. Schweder jonathanschweder@gmail.com

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Server ServerConfig `json:"server"`
	Routes Routes       `json:"routes"`
}

type Request

type Request struct {
	Url    string `json:"url"`
	Method string `json:"method"`
}

type Response

type Response struct {
	Status int    `json:"status"`
	Body   string `json:"body"`
}

type Route

type Route struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

type Routes

type Routes []Route

type Server

type Server struct {
	Config Config
}

func CreateHttpMockServer

func CreateHttpMockServer(file string) Server

func (Server) Handle

func (c Server) Handle(w http.ResponseWriter, r *http.Request)

func (Server) Run

func (c Server) Run()

type ServerConfig

type ServerConfig struct {
	Address string `json:"address"`
	Port    int    `json:"port"`
}

Jump to

Keyboard shortcuts

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