forked from timchenxiaoyu/goproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.go
51 lines (40 loc) · 741 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package goproxy
import (
"bufio"
//"encoding/base64"
"net"
//"strings"
"github.com/golang/glog"
)
type Server struct {
listener net.Listener
addr string
}
func NewServer(Addr string) *Server {
glog.V(4).Infoln("create server")
return &Server{
addr: Addr, }
}
func (s *Server) Start() {
var err error
s.listener, err = net.Listen("tcp", s.addr)
if err != nil {
glog.Fatal(err)
}
glog.Infof("proxy listen in %s, waiting for connection...\n", s.addr)
for {
conn, err := s.listener.Accept()
if err != nil {
glog.Error(err)
continue
}
go s.newConn(conn).serve()
}
}
func (s *Server) newConn(rwc net.Conn) *conn {
return &conn{
server: s,
rwc: rwc,
brc: bufio.NewReader(rwc),
}
}