Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Latest commit

 

History

History
145 lines (110 loc) · 4.17 KB

README.md

File metadata and controls

145 lines (110 loc) · 4.17 KB

中文

Boast

"I want track all requests, and replay it easily."

Integrate with Go HTTP servers

Install the boast package:

go get github.com/dcb9/boast

After installing, modify your server file

with default HTTP server

package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	"github.com/dcb9/boast"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page!")
	}))

-	// in old way
-	http.ListenAndServe(":8080", mux)
+	// in boast way
+	server := httptest.NewServer(mux)
+	addr, debugAddr := ":8080", ":8079"
+	boast.Serve(server, addr, debugAddr)
}

with Echo web framework

package main

import (
	"net/http"
	"net/http/httptest"
	"github.com/dcb9/boast"
	"github.com/labstack/echo"
)

func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})

-   e.Logger.Fatal(e.Start(":8080"))
+	server := httptest.NewServer(e)
+	addr, debugAddr := ":8080", ":8079"
+	boast.Serve(server, addr, debugAddr)
}

Run

Then run your server:

go run server.go

First request your server as usual, then you can visit debug panel ( http://localhost:8079 )

Standalone

Install

Download the latest binary file from the Releases page.

(darwin_amd64.tar.gz is for Mac OS X users)

Usage

$ cat .boast.json
{
	"debug_addr": ":8079",
	"list": [
		{ "url": "https://www.baidu.com/", "addr": ":8080" },
		{ "url": "https://github.com/", "addr": ":8081" }
	]
}

$ boast -c .boast.json

$ boast --help
Usage of boast:
  -c string
       config file path (default ".boast.json")

Sketch

HTTP Client                   Boast                       WebServer
| GET http://localhost:8080/   | Record and Reverse Proxy    | Response 200 OK
| ---------------------------> | --------------------------> | ------┐
|                              |                             |       |
|                              |     Record and Forward      |  <----┘
| <--------------------------- | <-------------------------- |

┌----------------------------------------------------------------------------┐
| url: http://localhost:8081                                                 |
| ---------------------------------------------------------------------------|
| All Transactions         ┌ - - - - - - - - - - - - - - - - - - - - - - - ┐ |
| ----------------------   | time: 10 hours ago  Client: 127.0.0.1         | |
| |GET / 200 OK 100 ms |   |                                               | |
| ----------------------   | Request                      [ Replay ]       | |
|                          | -   -   -   -   -   -   -   -   -   -   -   - | |
|                          | GET http://localhost/ HTTP/1.1                | |
|                          | User-Agent: curl/7.51.0                       | |
|                          | Accept: */*                                   | |
|                          |                                               | |
|                          | Response                                      | |
|                          | -   -   -   -   -   -   -   -   -   -   -   - | |
|                          | HTTP/1.1 200 OK                               | |
|                          | X-Server: HTTPLab                             | |
|                          | Date: Thu, 02 Mar 2017 02:25:27 GMT           | |
|                          | Content-Length: 13                            | |
|                          | Content-Type: text/plain; charset=utf-8       | |
|                          |                                               | |
|                          | Hello, World                                  | |
|                          └ - - - - - - - - - - - - - - - - - - - - - - - ┘ |
|                                                                            |
└----------------------------------------------------------------------------┘

Warning

DO NOT USE ON PRODUCTION!

Boast is heavily inspired by ngrok.