uri

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

OpenURI

Usage

Open the file.

o, err := uri.Open("/path/to/file")

Open the URL.

o, err := uri.Open("http://localhost")

with Google App Engine

o, err := uri.Open("http://localhost", uri.WithHTTPClient(urlfetch.Client(ctx)))

Example

	//
	// Open a local file
	//
	o, err := uri.Open("/path/to/file")
	if err != nil {
	    log.Fatal(err)
	}
	defer o.Close()
	
	b, _ := ioutil.ReadAll(o)
	log.Println(string(b))
	
	//
	// Open URL
	//
	o, err = uri.Open("http://localhost")
	if err != nil {
	    log.Fatal(err)
	}
	defer o.Close()
	
	b, _ = ioutil.ReadAll(o)
	log.Println(string(b))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(name string, options ...ClientOption) (io.ReadCloser, error)

Open opens an io.ReadCloser from a local file or URL

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps extended HTTP client helpers.

func New

func New(options ...ClientOption) (*Client, error)

New returns a Client

func (*Client) Open

func (c *Client) Open(name string) (io.ReadCloser, error)

Open opens either a response body from a given url, or a file from a given path.

type ClientOption

type ClientOption func(*Client) error

ClientOption type

func WithHTTPClient

func WithHTTPClient(v *http.Client) ClientOption

WithHttpClient returns a ClientOption that sets the http.Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL