當前位置: 首頁>>代碼示例>>Golang>>正文


Golang http.NewFileTransport函數代碼示例

本文整理匯總了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)に表示する
}
開發者ID:YuheiNakasaka,項目名稱:shakyo,代碼行數:7,代碼來源:main.go

示例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()
}
開發者ID:kity-xu,項目名稱:xuxiaodong,代碼行數:34,代碼來源:maketables.go

示例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)
}
開發者ID:hfeeki,項目名稱:http,代碼行數:7,代碼來源:main.go

示例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
}
開發者ID:expanse-project,項目名稱:go-expanse,代碼行數:9,代碼來源:httpclient.go

示例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
}
開發者ID:ruflin,項目名稱:go-ethereum,代碼行數:10,代碼來源:docserver.go

示例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
	}
}
開發者ID:bukalapak,項目名稱:fotomat,代碼行數:10,代碼來源:image-handler.go

示例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}
}
開發者ID:RickyS,項目名稱:Creep,代碼行數:10,代碼來源:creep.go

示例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))
}
開發者ID:treejames,項目名稱:simplecache,代碼行數:11,代碼來源:main.go

示例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
}
開發者ID:PDKK,項目名稱:contrib,代碼行數:12,代碼來源:service_loadbalancer.go

示例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))
}
開發者ID:kitwalker12,項目名稱:fotomat,代碼行數:12,代碼來源:handle.go

示例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
}
開發者ID:haramako,項目名稱:cfs,代碼行數:23,代碼來源:bucket.go

示例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
}
開發者ID:redcatmiss,項目名稱:gcc,代碼行數:17,代碼來源:regtest.go

示例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
}
開發者ID:TriangleGo,項目名稱:golang.org,代碼行數:19,代碼來源:maketables.go

示例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
}
開發者ID:gitter-badger,項目名稱:omise-go,代碼行數:18,代碼來源:fixtures_transport.go

示例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)
}
開發者ID:google,項目名稱:pprof,代碼行數:21,代碼來源:fetch_test.go


注:本文中的net/http.NewFileTransport函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。