uri

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 4 Imported by: 1

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