Initial commit

This commit is contained in:
Ian Gulliver
2023-04-25 14:26:46 -07:00
parent feb67dd5d4
commit 49de6d7daf
5 changed files with 170 additions and 0 deletions

40
proxy.go Normal file
View File

@@ -0,0 +1,40 @@
package proxy
import "net"
type Proxy struct {
backend *net.TCPAddr
listener *net.TCPListener
}
func NewProxy(backend *net.TCPAddr) (*Proxy, error) {
var err error
p := &Proxy{
backend: backend,
}
p.listener, err = net.ListenTCP("tcp", nil)
if err != nil {
return nil, err
}
go p.accept()
return p, nil
}
func (p *Proxy) Close() {
p.listener.Close()
}
func (p *Proxy) accept() {
for {
conn, err := p.listener.Accept()
if err != nil {
return
}
conn.Close()
}
}