urlio

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 13 Imported by: 0

README

urlio

ci Documentation Go Report Card

package urlio aims to provide io.Reader/io.Writer for resources corresponding to URLs. builtin support schemes

  • s3
  • gs
  • file
  • http
  • https

Note: As of v0.0.0, it is still a Reader only implementation.

Usage

see details in godoc

package main

import (
	"fmt"
	"io/ioutil"

	"github.com/mashiike/urlio"
)

func main() {
	reader, _ := urlio.NewReader("s3://example.com/example.txt")
	defer reader.Close()
	bytes, _ := ioutil.ReadAll(reader)
	fmt.Println(string(bytes))
}

LICENSE

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Constructors

func Constructors(constractorMap ConstructorMap)

Constructors adds the elements of the argument map to the function map of the constructor. Must be called before building a io.ReadCloser

func GSConfig

func GSConfig(opts ...option.ClientOption)

GSConfig sets GCP client Option

func HTTPConfig

func HTTPConfig(opts ...HTTPOption)

HTTPConfig sets HTTPOptions

func MustParse

func MustParse(rawurl string) *url.URL

MustParse as url.Parse. if error occted panic.

func NewReader

func NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to the URL scheme of the source.

Example
package main

import (
	"log"

	"github.com/mashiike/urlio"
)

func main() {
	reader, err := urlio.NewReader(
		urlio.MustParse("https://www.google.com/"),
	)
	if err != nil {
		log.Println(err)
		return
	}
	defer reader.Close()
}
Output:

func S3Config

func S3Config(cfgs ...*aws.Config)

S3Config sets AWS session Configure

Types

type Constructor

type Constructor interface {
	NewReader(*url.URL) (io.ReadCloser, error)
}

Constructor provides the construction function

type ConstructorMap

type ConstructorMap map[string]Constructor

ConstructorMap represents the correspondence between Scheme and Constructor

func New

func New() ConstructorMap

New create new constructorMap, for switch configuration

func (ConstructorMap) Constractors

func (m ConstructorMap) Constractors(constractorMap ConstructorMap)

Constractors adds the elements of the argument map to the function map of the constructor. Must be called before building a io.ReadCloser

func (ConstructorMap) NewReader

func (m ConstructorMap) NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to the URL scheme of the source.

type File

type File struct{}

File provides local FilySystem resource constructor func

func NewFile

func NewFile() *File

NewFile create File Resource Stream Constructor

func (*File) NewReader

func (c *File) NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to local FileSystem resource.

type GS

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

GS provides GCP CloucStorage constractor func

func NewGS

func NewGS(opts ...option.ClientOption) *GS

NewGS create File Resource Stream Constructor

func (*GS) Config

func (c *GS) Config(opts ...option.ClientOption)

Config sets GCP client Option

func (*GS) NewReader

func (c *GS) NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to gs resource.

type HTTP

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

HTTP provides HTTP/HTTPS request resource constructor func

func NewHTTP

func NewHTTP() *HTTP

NewHTTP create HTTP/HTTPS Resource Stream Constructor

func (*HTTP) Config

func (c *HTTP) Config(opts ...HTTPOption)

Config sets HTTPOptions

func (*HTTP) NewReader

func (c *HTTP) NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to http/https resource.

type HTTPOption

type HTTPOption interface {
	Apply(*HTTP)
}

A HTTPOption is an option for HTTP resource constructor.

func WithCheckStatus

func WithCheckStatus(check bool) HTTPOption

WithCheckStatus is HTTP/HTTPS scheme option. if set true, status 4xx, 5xx,... not 200 is error

func WithHTTPClient

func WithHTTPClient(client *http.Client) HTTPOption

WithHTTPClient is a HTTP/HTTPS scheme option. set *http.Client

func WithUserAgent

func WithUserAgent(agentName string) HTTPOption

WithUserAgent is a HTTP/HTTPS scheme option. set user-agent

type S3

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

S3 provides AWS S3 constractor func

func NewS3

func NewS3() *S3

NewS3 create AWS S3 Resource Stream Constructor

func (*S3) Config

func (c *S3) Config(cfgs ...*aws.Config)

Config sets AWS session Configure

func (*S3) NewReader

func (c *S3) NewReader(src *url.URL) (io.ReadCloser, error)

NewReader returns a new io.ReadCloser according to s3 resource.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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