Documentation ¶
Index ¶
- Constants
- type Switcheroo
- func NewSwitcheroo(namespace string, incomingPort int, logger *log.Logger) (*Switcheroo, error)
- func NewSwitcherooWithIptablesCmd(namespace string, incomingPort int, logger *log.Logger, ...) *Switcheroo
- func NewSwitcherooWithSudoIptables(namespace string, incomingPort int, logger *log.Logger) (*Switcheroo, error)
Constants ¶
View Source
const ( /* enables network and/or localhost routing; iptables is a bit * "low-level weird" in this regard, because loopback/localhost routing * and network/hardware-level routing occurs in different "chains"; so * a localhost rule won't affect "traffic from the outside", and vice * versa */ ENABLE_NETWORK = 1 << 0 ENABLE_LOCALHOST = 1 << 1 )
use with SetFlags()
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Switcheroo ¶
type Switcheroo struct { // Namespacing is required if you plan on running multiple // switcheroo-powered processes on the same computer Namespace string // The port we accept traffic on, seen from the outside IncomingPort int // Dynamic port range min/max PortMin int PortMax int // func mimicing exec.Command(...), but you can override it (e.g. we // support both `iptables` and `sudo iptables` via this interface) IptablesCmd func(args ...string) *exec.Cmd // If set, we log what happens. Can be nil. Logger *log.Logger // See SetFlags() Flags int }
You can change all these after NewSwitcheroo() and before switcheroo.Begin() *
func NewSwitcheroo ¶
returns Switcheroo that uses iptables as-is (so you must be root)
func NewSwitcherooWithSudoIptables ¶
func NewSwitcherooWithSudoIptables(namespace string, incomingPort int, logger *log.Logger) (*Switcheroo, error)
returns Switcheroo that executes iptables using sudo (so your user must have * sudo-access to iptables)
func (*Switcheroo) Begin ¶
func (s *Switcheroo) Begin() (net.Listener, func() error, error)
Begins the switcheroo process; returns a net.Listener you should start your * server on, and when you're ready to serve traffic, call the returned * function, which finalizes the process
func (*Switcheroo) Cleanup ¶
func (s *Switcheroo) Cleanup() error
Remove all switcheroo iptables rules
Click to show internal directories.
Click to hide internal directories.