jpillora / go-tcp-proxy

A small TCP proxy written in Go
MIT License
746 stars 197 forks source link

Refactor to package #2

Closed heewa closed 8 years ago

heewa commented 8 years ago

This should have the command behave the same, except you now need to run it like: go run cmd/tcp-proxy/main.go. But now you can also import and use this as a package, with all the stuff that are cmdline args in the program as parameters and settings on an instance of a Proxy struct (with sane defaults). Otherwise the behavior (and the meat of the code) is unchanged.

package some-other-project

import "github.com/lumanetworks/go-tcp-proxy"

func Yay(localConnection *net.TCPConn, localAddress, remoteAddress *net.TCPAddr) {
    p := proxy.New(localConnection, localAddress, remoteAddress)
    p.Log.Color = true
    p.Nagles = true
    p.Matcher = myMatcher

    p.Start()
}

Changes:

jpillora commented 8 years ago

Awesome, thanks!