openany

package module
v0.0.0-...-f6c635c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 6 Imported by: 0

README

OpenAny

This is a little utility to mimic os.Open("/some/file") but have it be able to open files for more sources.

  • local filesystem
  • aws s3
  • http/https

The goal is to make it easy to implement your own backend and have the url scheme determine which backend to use.

usage

The main way to use this is in place of os.Open. The interface uses io.ReadCloser instead of os.File like so:

type Opener func(name string) (io.ReadCloser, error)

Be sure to call Close() on the returned io.ReadCloser.

Here are some examples of how you could use this in your golang code.

Open a local file.

readcloser, err := openany.Open("/some/local/file")
defer readcloser.Close()

Open a URL.

readcloser, err := openany.Open("https://some/url")
defer readcloser.Close()

Open from AWS S3.

readcloser, err := openany.Open("s3://bucket/some/object/key")
defer readcloser.Close()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(uri string) (io.ReadCloser, error)

func Register

func Register(scheme string, backend Opener)

Types

type Opener

type Opener func(string) (io.ReadCloser, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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