Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/utahta/go-openuri
Open file and url in the same interface
https://github.com/utahta/go-openuri
go golang openuri
Last synced: about 2 months ago
JSON representation
Open file and url in the same interface
- Host: GitHub
- URL: https://github.com/utahta/go-openuri
- Owner: utahta
- Created: 2017-01-22T08:15:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-03T10:45:03.000Z (almost 8 years ago)
- Last Synced: 2024-06-18T21:44:48.965Z (7 months ago)
- Topics: go, golang, openuri
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 10
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenURI
[![GitHub release](https://img.shields.io/github/release/utahta/go-openuri.svg)](https://github.com/utahta/go-openuri/releases)
[![Build Status](https://travis-ci.org/utahta/go-openuri.svg?branch=master)](https://travis-ci.org/utahta/go-openuri)Easy way to open an io.ReadCloser from a local file and URL.
## Install
```
$ go get -u github.com/utahta/go-openuri
```## Usage
```go
import "github.com/utahta/go-openuri"
```Open the file.
```go
o, err := openuri.Open("/path/to/file")
```Open the URL.
```go
o, err := openuri.Open("http://localhost")
```with Google App Engine
```go
o, err := openuri.Open("http://localhost", openuri.WithHTTPClient(urlfetch.Client(ctx)))
```## Example
```go
package mainimport (
"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