resource

package
v0.0.0-...-21d6f6e Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Resource pacakge is for loading resources identified by a URL. Supports for different protocols such as http, https, strings, files, exist. Other modules can register additional support for protocols such as zookeeper.

Index

Constants

View Source
const (
	ResourceHttp   = "http"
	ResourceHttps  = "https"
	ResourceString = "string"
	ResourceFile   = "file"
)

Variables

View Source
var HttpHeaderContextKey httpHeaderContextKey = 1

Functions

func ContextGetHttpHeader

func ContextGetHttpHeader(ctx context.Context) http.Header

func ContextPutHttpHeader

func ContextPutHttpHeader(ctx context.Context, header http.Header) context.Context

func Fetch

func Fetch(ctx context.Context, url string) ([]byte, error)

This is the function most user will use. Using the protocol/scheme provided with the url, different implementations will be invoked. There are standard implementations in this package (see constants). Other packages using different backends can call the `Register` function to register different implementations.

func FileResource

func FileResource(ctx context.Context, url string) ([]byte, error)

func HttpResource

func HttpResource(ctx context.Context, url string) ([]byte, error)

func Register

func Register(protocol string, source ResourceFunc)

Packages providing different backend support for this should call this in its `init()` function.

Types

type NotSupported

type NotSupported struct {
	Protocol string
}

func (*NotSupported) Error

func (this *NotSupported) Error() string

type ResourceFunc

type ResourceFunc func(context.Context, string) ([]byte, error)

Jump to

Keyboard shortcuts

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