static

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: Apache-2.0 Imports: 16 Imported by: 54

Documentation

Overview

Package static provides a modifier that allows Martian to return static files local to Martian. The static modifier does not support setting explicit path mappings via the JSON API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Modifier

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

Modifier is a martian.RequestResponseModifier that routes reqeusts to rootPath and serves the assets there, while skipping the HTTP roundtrip.

func NewModifier

func NewModifier(rootPath string) *Modifier

NewModifier constructs a static.Modifier that takes a path to serve files from, as well as an optional mapping of request paths to local file paths (still rooted at rootPath).

func (*Modifier) ModifyRequest

func (s *Modifier) ModifyRequest(req *http.Request) error

ModifyRequest marks the context to skip the roundtrip and downgrades any https requests to http.

func (*Modifier) ModifyResponse

func (s *Modifier) ModifyResponse(res *http.Response) error

ModifyResponse reads the file rooted at rootPath joined with the request URL path. In the case that the the request path is a key in s.explicitPaths, ModifyRequest will attempt to open the file located at s.rootPath joined by the value in s.explicitPaths (keyed by res.Request.URL.Path). In the case that the file cannot be found, the response will be a 404. ModifyResponse will return a 404 for any path that is defined in s.explictPaths and that does not exist locally, even if that file does exist in s.rootPath.

func (*Modifier) SetExplicitPathMappings

func (s *Modifier) SetExplicitPathMappings(ep map[string]string)

SetExplicitPathMappings sets an optional mapping of request paths to local file paths rooted at s.rootPath.

Jump to

Keyboard shortcuts

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