resource

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package resource manages http resources that you serve based on a static path to the resource. Example resources include custom generated CSV, PDF and image files.

Index

Constants

This section is empty.

Variables

View Source
var ResourcePathPrefix = ""

ResourcePathPrefix is a prefix you can use in front of all goradd rest paths, like a directory path, to indicate that this is a goradd rest path.

Functions

func HandleRequest

func HandleRequest(w http.ResponseWriter, r *http.Request) bool

func Redirect

func Redirect(url string)

Redirect aborts the current page load and tells the browser to load a different url.

func RegisterPath

func RegisterPath(path string, handler ResourcePathHandler)

RegisterPath associates the given URL path with the given creation function. Call this from an init() function. Afterwards, whenever a user navigates to the given path, the result of the query will be presented to the user.

Types

type HttpError

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

HttpError represents an error response to a http request.

func (*HttpError) Send

func (e *HttpError) Send(errCode int)

Send will cause the page to error with the given http error code.

func (*HttpError) SetResponseHeader

func (e *HttpError) SetResponseHeader(key, value string)

SetResponseHeader sets a key-value in the header response.

type ResourceManager

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

The ResourceManager is a singleton global that manages the registration and deployment of rest paths. It acts like a URL router, returning the ResourcePathHandler that corresponds to a particular URL path. init() functions should be created for each path that associates a function to create a rest path, with the URL that corresponds to the path.

func GetResourceManager

func GetResourceManager() *ResourceManager

GetResourceManager returns the current resource manager.

type ResourceManagerI

type ResourceManagerI interface {
	RegisterPath(path string, handler ResourcePathHandler)
}

type ResourcePathHandler

type ResourcePathHandler func(ctx context.Context, buf *bytes.Buffer) (headers map[string]string, err error)

Jump to

Keyboard shortcuts

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