使用Go语言+goproxy库编写的http代理服务器+图片cache保存 第一版完成
用法:
1、安装Go 1.5.x
2、命令行设置环境变量GOSRC(Windows下设置到“我的电脑”里面)
3、安装goproxy库:go get github.com/elazarl/goproxy
4、运行脚本:go run go-httproxy-imagedumper.go
5、可以用go build创建exe版本
用法:
1、安装Go 1.5.x
2、命令行设置环境变量GOSRC(Windows下设置到“我的电脑”里面)
3、安装goproxy库:go get github.com/elazarl/goproxy
4、运行脚本:go run go-httproxy-imagedumper.go
5、可以用go build创建exe版本
package main
import (
"crypto/sha1"
"errors"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
// "net/http/httputil"
"os"
"os/signal"
"path"
"regexp"
"sync"
// "time"
"github.com/elazarl/goproxy"
// "github.com/elazarl/goproxy/transport"
)
//--------------------------------------------------------------------------- Code Copied from examples/goproxy-httpdump
type FileStream struct {
path string
f *os.File
}
func NewFileStream(path string) *FileStream {
return &FileStream{path, nil}
}
func (fs *FileStream) Write(b []byte) (nr int, err error) {
if fs.f == nil {
fs.f, err = os.Create(fs.path)
if err != nil {
return 0, err
}
}
return fs.f.Write(b)
}
func (fs *FileStream) Close() error {
fmt.Println("Close", fs.path)
if fs.f == nil {
return errors.New("FileStream was never written into")
}
return fs.f.Close()
}
//--------------------------------------------------------------------------- Code Copied