按需修改

addon-dailer
ZhouYixun 3 years ago
parent 8522ebedb0
commit 87d9c93f0b

@ -70,20 +70,6 @@ func NewCA(path string) (*CA, error) {
return ca, nil
}
func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return
}
defer dst.Close()
return io.Copy(dst, src)
}
func getStorePath(path string) (string, error) {
if path == "" {
homeDir, err := os.UserHomeDir()
@ -261,15 +247,19 @@ func (ca *CA) saveCert() error {
}
defer file.Close()
err = ca.saveCertTo(file)
if err != nil {
return err
}
cerFile, err := os.Create(ca.caCertCerFile())
if err != nil {
return err
}
defer cerFile.Close()
CopyFile(cerFile.Name(), file.Name())
err = ca.saveCertTo(cerFile)
if err != nil {
return err
}
return err
}

@ -73,8 +73,8 @@ type Middle struct {
Server *http.Server
}
func NewMiddle(proxy *Proxy,path string) (Interceptor, error) {
ca, err := cert.NewCA(path)
func NewMiddle(proxy *Proxy,caPath string) (Interceptor, error) {
ca, err := cert.NewCA(caPath)
if err != nil {
return nil, err
}

@ -19,6 +19,7 @@ type Options struct {
Addr string
StreamLargeBodies int64
SslInsecure bool
CaRootPath string
}
type Proxy struct {
@ -30,7 +31,7 @@ type Proxy struct {
Addons []addon.Addon
}
func NewProxy(opts *Options,path string) (*Proxy, error) {
func NewProxy(opts *Options) (*Proxy, error) {
proxy := new(Proxy)
proxy.Version = "0.1.5"
@ -65,7 +66,7 @@ func NewProxy(opts *Options,path string) (*Proxy, error) {
},
}
interceptor, err := NewMiddle(proxy,path)
interceptor, err := NewMiddle(proxy, opts.CaRootPath)
if err != nil {
return nil, err
}

Loading…
Cancel
Save