Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

Delta - HTTP Shadow Proxy Server Written in Go

I just created a tool named "Delta". It's the first Go code for me. The reason why I created and wrote it in Go is that I just wanted to learn Go by writing some lines of code ;)

What's "Delta"?

Delta is an HTTP shadow proxy server that sits between clients and your server(s) to enable "shadow requests".

It's actually just a Go port of Kage. You can consult the documentation of Kage for reasons why this software matters ;)

Usage

package main

import (
    "github.com/kentaro/delta"
    "log"
    "net/http"
    "time"
)

func main() {
    server := delta.NewServer("127.0.0.1", 8484)

    server.AddMasterBackend("production", "127.0.0.1", 8080)
    server.AddBackend("testing", "127.0.0.1", 8081)

    server.OnSelectBackend(func(req *http.Request) []string {
        if req.Method == "GET" {
            return []string{"production", "testing"}
        } else {
            return []string{"production"}
        }
    })

    server.OnMungeHeader(func(backend string, header *http.Header) {
        if backend == "testing" {
            header.Add("X-Delta-Sandbox", "1")
        }
    })

    server.OnBackendFinished(func(responses map[string]*delta.Response) {
        for backend, response := range responses {
            log.Printf("%s [%d ms]: %s", backend, (response.Elapsed / time.Millisecond), response.Data)
        }
    })

    server.Run()
}

SEE ALSO

  • Kage
  • Geets
  • Gor
    • It's a tool written in Go to deal with a similar problem