Skip to content

Latest commit

 

History

History
81 lines (61 loc) · 1.43 KB

README.md

File metadata and controls

81 lines (61 loc) · 1.43 KB

OpenURI

GitHub release Build Status

Easy way to open an io.ReadCloser from a local file and URL.

Install

$ go get -u github.com/utahta/go-openuri

Usage

import "github.com/utahta/go-openuri"

Open the file.

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

Open the URL.

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

with Google App Engine

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

Example

package main

import (
	"log"
	"io/ioutil"

	"github.com/utahta/go-openuri"
)

func main() {
	//
	// Open a local file
	//
	o, err := openuri.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 = openuri.Open("http://localhost")
	if err != nil {
	    log.Fatal(err)
	}
	defer o.Close()
	
	b, _ = ioutil.ReadAll(o)
	log.Println(string(b))
}

Contributing

  1. Fork it ( https://github.com/utahta/go-openuri/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request