本文整理汇总了Golang中github.com/phuslu/goproxy/httpproxy/filters.LookupConfigStoreURI函数的典型用法代码示例。如果您正苦于以下问题:Golang LookupConfigStoreURI函数的具体用法?Golang LookupConfigStoreURI怎么用?Golang LookupConfigStoreURI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LookupConfigStoreURI函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewFilter
func NewFilter(config *Config) (_ filters.Filter, err error) {
var gfwlist GFWList
gfwlist.Encoding = config.GFWList.Encoding
gfwlist.Filename = config.GFWList.File
gfwlist.Duration = time.Duration(config.GFWList.Duration) * time.Second
gfwlist.URL, err = url.Parse(config.GFWList.URL)
if err != nil {
return nil, err
}
store, err := storage.OpenURI(filters.LookupConfigStoreURI(filterName))
if err != nil {
return nil, err
}
if _, err := store.HeadObject(gfwlist.Filename); err != nil {
return nil, err
}
autoproxy2pac := &AutoProxy2Pac{
Sites: config.Sites,
}
object, err := store.GetObject(gfwlist.Filename, -1, -1)
if err != nil {
return nil, err
}
rc := object.Body()
defer rc.Close()
err = autoproxy2pac.Read(rc)
if err != nil {
return nil, err
}
f1, err := filters.NewFilter(config.Transport)
if err != nil {
return nil, err
}
f2, ok := f1.(filters.RoundTripFilter)
if !ok {
return nil, fmt.Errorf("%#v was not a filters.RoundTripFilter", f1)
}
f := &Filter{
Store: store,
Sites: httpproxy.NewHostMatcher(config.Sites),
GFWList: &gfwlist,
AutoProxy2Pac: autoproxy2pac,
Transport: f2,
}
go onceUpdater.Do(f.updater)
return f, nil
}
开发者ID:GitDot,项目名称:goproxy,代码行数:59,代码来源:autoproxy.go
示例2: init
func init() {
filename := filterName + ".json"
config, err := NewConfig(filters.LookupConfigStoreURI(filterName), filename)
if err != nil {
glog.Fatalf("NewConfig(%#v) failed: %s", filename, err)
}
err = filters.Register(filterName, &filters.RegisteredFilter{
New: func() (filters.Filter, error) {
return NewFilter(config)
},
})
if err != nil {
glog.Fatalf("Register(%#v) error: %s", filterName, err)
}
}
开发者ID:nonovc,项目名称:goproxy,代码行数:17,代码来源:php.go
示例3: main
func main() {
configUri := filters.LookupConfigStoreURI("main.json")
filename := "main.json"
config, err := NewConfig(configUri, filename)
if err != nil {
fmt.Printf("NewConfig(%#v) failed: %s", filename, err)
return
}
pidfile := ""
flag.StringVar(&pidfile, "pidfile", "", "goproxy pidfile")
flag.StringVar(&config.Addr, "addr", config.Addr, "goproxy listen address")
flag.StringVar(&config.GroupCache.Addr, "groupcache-addr", config.GroupCache.Addr, "groupcache listen address")
if config.LogToStderr || runtime.GOOS == "windows" {
logToStderr := true
for i := 1; i < len(os.Args); i++ {
if strings.HasPrefix(os.Args[i], "-logtostderr=") {
logToStderr = false
break
}
}
if logToStderr {
flag.Set("logtostderr", "true")
}
}
flag.Parse()
if runtime.GOOS != "windows" && pidfile != "" {
if err = ioutil.WriteFile(pidfile, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil {
glog.Fatalf("Write pidfile(%s) error: %s", pidfile, err)
}
}
var ln0 net.Listener
if config.GroupCache.Addr != "" {
peers := groupcache.NewHTTPPool("http://" + config.GroupCache.Addr)
peers.Set(config.GroupCache.Peers...)
ln0, err = net.Listen("tcp", config.GroupCache.Addr)
if err != nil {
glog.Fatalf("ListenTCP(%s) error: %s", config.GroupCache.Addr, err)
}
go http.Serve(ln0, peers)
}
fmt.Fprintf(os.Stderr, `------------------------------------------------------
GoProxy Version : %s (go/%s %s/%s)
Listen Address : %s
RoundTrip Filters : %v
Pac Server : http://%s/proxy.pac
------------------------------------------------------
`, Version, runtime.Version(), runtime.GOOS, runtime.GOARCH,
config.Addr,
strings.Join(config.Filters.RoundTrip, ","),
config.Addr)
requestFilters, roundtripFilters, responseFilters := getFilters(config)
var tlsConfig *tls.Config
if config.Http.Mode == "h2" {
readPem := func(object string) []byte {
store, err := storage.OpenURI(configUri)
if err != nil {
glog.Fatalf("store.OpenURI(%v) error: %s", configUri, err)
}
o, err := store.GetObject(object, -1, -1)
if err != nil {
glog.Fatalf("store.GetObject(%v) error: %s", object, err)
}
rc := o.Body()
defer rc.Close()
b, err := ioutil.ReadAll(rc)
if err != nil {
glog.Fatalf("ioutil.ReadAll error: %s", err)
}
return b
}
certPem := readPem(config.Http.Certificate)
keyPem := readPem(config.Http.Certificate)
tlsCert, err := tls.X509KeyPair(certPem, keyPem)
if err != nil {
glog.Fatalf("tls.X509KeyPair error: %s", err)
}
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{tlsCert},
}
}
listenOpts := &httpproxy.ListenOptions{TLSConfig: tlsConfig}
if strings.HasPrefix(config.Http.Mode, "h2") {
// http2.VerboseLogs = true
listenOpts.KeepAlivePeriod = 3 * time.Minute
}
//.........这里部分代码省略.........
开发者ID:nonovc,项目名称:goproxy,代码行数:101,代码来源:main.go
示例4: NewFilter
func NewFilter(config *Config) (_ filters.Filter, err error) {
var gfwlist GFWList
gfwlist.Encoding = config.GFWList.Encoding
gfwlist.Filename = config.GFWList.File
gfwlist.Duration = time.Duration(config.GFWList.Duration) * time.Second
gfwlist.URL, err = url.Parse(config.GFWList.URL)
if err != nil {
return nil, err
}
store, err := storage.OpenURI(filters.LookupConfigStoreURI(filterName))
if err != nil {
return nil, err
}
if _, err := store.HeadObject(gfwlist.Filename); err != nil {
return nil, err
}
autoproxy2pac := &AutoProxy2Pac{
Sites: config.Sites,
}
object, err := store.GetObject(gfwlist.Filename, -1, -1)
if err != nil {
return nil, err
}
rc := object.Body()
defer rc.Close()
var r io.Reader
br := bufio.NewReader(rc)
if data, err := br.Peek(20); err == nil {
if bytes.HasPrefix(data, []byte("[AutoProxy ")) {
r = br
} else {
r = base64.NewDecoder(base64.StdEncoding, br)
}
}
err = autoproxy2pac.Read(r)
if err != nil {
return nil, err
}
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
}
f := &Filter{
Store: store,
Sites: httpproxy.NewHostMatcher(config.Sites),
GFWList: &gfwlist,
AutoProxy2Pac: autoproxy2pac,
Transport: transport,
UpdateChan: make(chan struct{}),
}
go onceUpdater.Do(f.updater)
return f, nil
}
开发者ID:sunjiahz,项目名称:goproxy,代码行数:64,代码来源:autoproxy.go
注:本文中的github.com/phuslu/goproxy/httpproxy/filters.LookupConfigStoreURI函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论