本文整理匯總了Golang中net/http.NewFileTransport函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFileTransport函數的具體用法?Golang NewFileTransport怎麽用?Golang NewFileTransport使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFileTransport函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
tr := &http.Transport{}
tr.RegisterProtocol("file", http.NewFileTransport(http.Dir("/"))) // http.Dir()は定義したProtocolのrootディレクトリを指定
c := &http.Client{Transport: tr}
r, _ := c.Get("file:///.DS_Store") // rootディレクトリの.DS_Storeにクライアントからアクセスする
io.Copy(os.Stdout, r.Body) // Copy(dst,src)なのでGetした結果(r.Body)を標準出力(os.Stdout)に表示する
}
示例2: main
func main() {
flag.Parse()
// Read the CLDR zip file.
if *localFiles {
pwd, _ := os.Getwd()
*url = "file://" + path.Join(pwd, path.Base(*url))
}
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
c := &http.Client{Transport: t}
resp, err := c.Get(*url)
if err != nil {
log.Fatalf("HTTP GET: %v", err)
}
if resp.StatusCode != 200 {
log.Fatalf(`bad GET status for "%q": %q`, *url, resp.Status)
}
r := resp.Body
defer r.Close()
d := &cldr.Decoder{}
d.SetDirFilter("main", "supplemental")
d.SetSectionFilter("localeDisplayNames")
data, err := d.DecodeZip(r)
if err != nil {
log.Fatalf("DecodeZip: %v", err)
}
b := builder{
data: data,
group: make(map[string]*group),
}
b.generate()
}
示例3: main
func main() {
tr := &http.Transport{}
tr.RegisterProtocol("file", http.NewFileTransport(http.Dir(".")))
c := &http.Client{Transport: tr}
r, _ := c.Get("file:///main.go")
io.Copy(os.Stdout, r.Body)
}
示例4: New
func New(docRoot string) (self *HTTPClient) {
self = &HTTPClient{
Transport: &http.Transport{},
DocRoot: docRoot,
schemes: []string{"file"},
}
self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot)))
return
}
示例5: New
func New(docRoot string) (self *DocServer) {
self = &DocServer{
Transport: &http.Transport{},
DocRoot: docRoot,
schemes: []string{"file"},
}
self.DocRoot = "/tmp/"
self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot)))
return
}
示例6: poolInit
func poolInit(limit int) {
if *localImageDirectory != "" {
transport.RegisterProtocol("file", http.NewFileTransport(http.Dir(*localImageDirectory)))
}
pool = make(chan bool, limit)
for i := 0; i < limit; i++ {
pool <- true
}
}
示例7: init
func init() {
// Bug: What if there is a newline in the "wrong" place?
urlFindRe = regexp.MustCompile(`href="((https?|file)://[^">#\?]+)`) // Note the back-quotes
fileRe = regexp.MustCompile(`(file)://`)
urlRejectRe = regexp.MustCompile(`\.(css|ico|js|py|pdf|png|mp3|mp4|jpg|jpeg|swf|exe|dll|so|lib)\/?$`)
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
fileClient = &http.Client{Transport: t}
}
示例8: main
func main() {
proxy := httputil.ReverseProxy{
Transport: http.NewFileTransport(http.Dir(CACHE_PATH)),
Director: director,
}
http.HandleFunc("/", proxy.ServeHTTP)
log.Println("Running...")
panic(http.ListenAndServe(":8080", nil))
}
示例9: newStaticPageHandler
// newStaticPageHandler returns a staticPageHandles with the contents of pagePath loaded and ready to serve
func newStaticPageHandler(errorPage string, defaultErrorPage string) *staticPageHandler {
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
c := &http.Client{Transport: t}
s := &staticPageHandler{c: c}
if err := s.loadUrl(errorPage); err != nil {
s.loadUrl(defaultErrorPage)
}
return s
}
示例10: handleInit
func handleInit() {
pool := thumbnail.NewPool(*maxImageThreads, 1)
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
if *localImageDirectory != "" {
transport.RegisterProtocol("file", http.NewFileTransport(http.Dir(*localImageDirectory)))
}
client := &http.Client{Transport: http.RoundTripper(transport), Timeout: *fetchTimeout}
http.Handle("/", thumbnail.NewProxy(director, pool, *maxPrefetch+*maxImageThreads, client))
}
示例11: fetch
func fetch(_url *url.URL) ([]byte, error) {
t := &http.Transport{}
if isWindows() {
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("")))
} else {
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
}
c := &http.Client{Transport: t}
res, err := c.Get(_url.String())
if err != nil {
return nil, err
}
defer res.Body.Close()
contents, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
return contents, nil
}
示例12: openReader
// openReader opens the url or file given by url and returns it as an io.ReadCloser
// or nil on error.
func openReader(url string) io.ReadCloser {
if *localFiles {
pwd, _ := os.Getwd()
url = "file://" + path.Join(pwd, path.Base(url))
}
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
c := &http.Client{Transport: t}
resp, err := c.Get(url)
Error(err)
if resp.StatusCode != 200 {
Error(fmt.Errorf(`bad GET status for "%s": %s`, url, resp.Status))
}
return resp.Body
}
示例13: openReader
// openReader opens the URL or file given by url and returns it as an io.ReadCloser
// or nil on error.
func openReader(url *string) (io.ReadCloser, error) {
if *localFiles {
pwd, _ := os.Getwd()
*url = "file://" + path.Join(pwd, path.Base(*url))
}
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
c := &http.Client{Transport: t}
resp, err := c.Get(*url)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf(`bad GET status for "%s": %s`, *url, resp.Status)
}
return resp.Body, nil
}
示例14: NewFixturesTransport
func NewFixturesTransport(dir string) (*FixturesTransport, error) {
if dir == "" {
dir = filepath.Join(
build.Default.GOPATH, "src",
"github.com/omise/omise-go",
"testdata/fixtures",
)
}
if fi, e := os.Lstat(dir); e != nil {
return nil, e
} else if !fi.IsDir() {
return nil, errors.New(dir + " is not a directory.")
}
backing := http.NewFileTransport(http.Dir(dir))
return &FixturesTransport{backing, dir}, nil
}
示例15: stubHTTPGet
// stubHTTPGet intercepts a call to http.Get and rewrites it to use
// "file://" to get the profile directly from a file.
func stubHTTPGet(source string, _ time.Duration) (*http.Response, error) {
url, err := url.Parse(source)
if err != nil {
return nil, err
}
values := url.Query()
file := values.Get("file")
if file == "" {
return nil, fmt.Errorf("want .../file?profile, got %s", source)
}
t := &http.Transport{}
t.RegisterProtocol("file", http.NewFileTransport(http.Dir("testdata/")))
c := &http.Client{Transport: t}
return c.Get("file:///" + file)
}