rest

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PATH_HEADER   = "X-Prudence-Path"
	CACHED_HEADER = "X-Prudence-Cached"
)
View Source
const (
	PATH_VARIABLE    = "__path"
	PATH_VARIABLE_RE = `(?P<` + PATH_VARIABLE + `>.*)`
)

Variables

View Source
var DefaultNotFound defaultNotFound
View Source
var PathTemplateAll = &PathTemplate{"", nil}

Functions

func AddCacheControl

func AddCacheControl(context *fasthttp.RequestCtx, value string)

func AddContentEncoding

func AddContentEncoding(context *fasthttp.RequestCtx, value string)

func AddETag

func AddETag(context *fasthttp.RequestCtx, eTag string)

func CallJavaScript

func CallJavaScript(runtime *goja.Runtime, function JavaScriptFunc, arguments ...interface{}) interface{}

func CreateFacet

func CreateFacet(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func CreateResource

func CreateResource(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func CreateRoute

func CreateRoute(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func CreateRouter

func CreateRouter(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func CreateServer

func CreateServer(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func CreateStatic

func CreateStatic(config ard.StringMap, context *js.Context) (interface{}, error)

CreateFunc signature

func GetContentEncoding

func GetContentEncoding(context *fasthttp.RequestCtx) string

func GetETag

func GetETag(context *fasthttp.RequestCtx) string

func GetEncodingType

func GetEncodingType(name string) platform.EncodingType

func GetLastModified

func GetLastModified(context *fasthttp.RequestCtx) time.Time

func GetQuery

func GetQuery(context *fasthttp.RequestCtx) map[string][]string

func Handled

func Handled(context *Context) bool

HandleFunc signature

func IfNoneMatch

func IfNoneMatch(context *fasthttp.RequestCtx, eTag string) bool

func NotFound

func NotFound(context *fasthttp.RequestCtx) bool

func ParseAccept

func ParseAccept(context *Context) []string

func SetBestEncodeWriter

func SetBestEncodeWriter(context *Context)

Types

type CaptureFunc

type CaptureFunc func(name string, value string)

type CaptureWriter

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

func NewCaptureWriter

func NewCaptureWriter(writer io.Writer, name string, capture CaptureFunc) *CaptureWriter

func (*CaptureWriter) Close

func (self *CaptureWriter) Close() error

io.Closer interface

func (*CaptureWriter) GetWrappedWriter

func (self *CaptureWriter) GetWrappedWriter() io.Writer

WrappingWriter interface

func (*CaptureWriter) Write

func (self *CaptureWriter) Write(b []byte) (int, error)

io.Writer interface

type Context

type Context struct {
	Context     *fasthttp.RequestCtx
	Name        string
	Log         logging.Logger
	Debug       bool
	Variables   ard.StringMap
	Path        string
	Method      string
	Query       map[string][]string
	ContentType string
	CharSet     string
	Language    string
	Done        bool
	Created     bool
	Async       bool

	CacheDuration float64 // seconds
	CacheKey      string
	CacheGroups   []string
	Signature     string
	WeakSignature bool
	Timestamp     time.Time
	// contains filtered or unexported fields
}

func NewContext

func NewContext(context *fasthttp.RequestCtx) *Context

func (*Context) Copy

func (self *Context) Copy() *Context

func (*Context) DeleteCachedRepresentation

func (self *Context) DeleteCachedRepresentation()

func (*Context) DescribeCachedRepresentation

func (self *Context) DescribeCachedRepresentation(cached *platform.CachedRepresentation) bool

func (*Context) ETag

func (self *Context) ETag() string

func (*Context) Embed

func (self *Context) Embed(function goja.FunctionCall, runtime *goja.Runtime) goja.Value

func (*Context) EndCapture

func (self *Context) EndCapture() error

func (*Context) EndRender

func (self *Context) EndRender() error

func (*Context) EndSignature

func (self *Context) EndSignature() error

func (*Context) Error

func (self *Context) Error(err error)

func (*Context) GetCachedRepresentationBody

func (self *Context) GetCachedRepresentationBody(cached *platform.CachedRepresentation) ([]byte, bool)

func (*Context) LoadCachedRepresentation

func (self *Context) LoadCachedRepresentation() (platform.CacheKey, *platform.CachedRepresentation, bool)

func (*Context) NewCacheKey

func (self *Context) NewCacheKey() platform.CacheKey

func (*Context) NewCachedRepresentation

func (self *Context) NewCachedRepresentation(withBody bool) *platform.CachedRepresentation

func (*Context) NewCachedRepresentationFromBody

func (self *Context) NewCachedRepresentationFromBody(encoding platform.EncodingType, body []byte) *platform.CachedRepresentation

func (*Context) PresentCachedRepresentation

func (self *Context) PresentCachedRepresentation(cached *platform.CachedRepresentation, withBody bool) bool

func (*Context) Rename added in v1.0.1

func (self *Context) Rename(name string) *Context

func (*Context) Request

func (self *Context) Request() string

func (*Context) StartCapture

func (self *Context) StartCapture(name string)

func (*Context) StartRender

func (self *Context) StartRender(renderer string, resolve js.ResolveFunc) error

func (*Context) StartSignature

func (self *Context) StartSignature()

Calculating a signature from the body is not that great. It saves bandwidth but not computing resources, as we still need to generate the body in order to calculate the signature. Ideally, the signature should be based on the data sources used to generate the page.

https://www.mnot.net/blog/2007/08/07/etags http://www.tbray.org/ongoing/When/200x/2007/07/31/Design-for-the-Web

func (*Context) StoreCachedRepresentation

func (self *Context) StoreCachedRepresentation(withBody bool)

func (*Context) StoreCachedRepresentationFromBody

func (self *Context) StoreCachedRepresentationFromBody(encoding platform.EncodingType, body []byte)

func (*Context) Write

func (self *Context) Write(b []byte) (int, error)

io.Writer

func (*Context) WriteCachedRepresentation

func (self *Context) WriteCachedRepresentation(cached *platform.CachedRepresentation) (bool, int, error)

func (*Context) WriteString

func (self *Context) WriteString(s string) (int, error)

type EncodeWriter

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

func NewEncodeWriter

func NewEncodeWriter(writer io.Writer, type_ platform.EncodingType) *EncodeWriter

func (*EncodeWriter) Close

func (self *EncodeWriter) Close() error

io.Closer interface

func (*EncodeWriter) GetWrappedWriter

func (self *EncodeWriter) GetWrappedWriter() io.Writer

WrappingWriter interface

func (*EncodeWriter) Write

func (self *EncodeWriter) Write(b []byte) (int, error)

io.Writer interface

type Facet

type Facet struct {
	*Route

	Representations Representations
}

func NewFacet

func NewFacet(name string) *Facet

func (*Facet) FindRepresentation

func (self *Facet) FindRepresentation(context *Context) (*Representation, string, bool)

func (*Facet) Handle

func (self *Facet) Handle(context *Context) bool

Handler interface HandleFunc signature

type HandleFunc

type HandleFunc func(context *Context) bool

func GetHandleFunc

func GetHandleFunc(value interface{}) (HandleFunc, error)

type Handler

type Handler interface {
	Handle(context *Context) bool
}

type HashWriter

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

func NewHashWriter

func NewHashWriter(writer io.Writer) *HashWriter

func (*HashWriter) Close

func (self *HashWriter) Close() error

io.Closer interface

func (*HashWriter) GetWrappedWriter

func (self *HashWriter) GetWrappedWriter() io.Writer

WrappingWriter interface

func (*HashWriter) Hash

func (self *HashWriter) Hash() string

func (*HashWriter) Write

func (self *HashWriter) Write(b []byte) (int, error)

io.Writer interface

type JavaScriptFunc

type JavaScriptFunc = func(goja.FunctionCall) goja.Value

type Logger

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

func (Logger) Printf

func (self Logger) Printf(format string, args ...interface{})

fasthttp.Logger interface

type PathTemplate

type PathTemplate struct {
	Template          string
	RegularExpression *regexp.Regexp
}

func NewPathTemplate

func NewPathTemplate(path string) (*PathTemplate, error)

func (*PathTemplate) Match

func (self *PathTemplate) Match(path string) map[string]string

type PathTemplates

type PathTemplates []*PathTemplate

func NewPathTemplates

func NewPathTemplates(paths ...string) (PathTemplates, error)

func (PathTemplates) MatchAny

func (self PathTemplates) MatchAny(path string) map[string]string

type RenderWriter

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

func NewRenderWriter

func NewRenderWriter(writer io.Writer, renderer string, resolve js.ResolveFunc) (*RenderWriter, error)

func (*RenderWriter) Close

func (self *RenderWriter) Close() error

io.Closer interface

func (*RenderWriter) GetWrappedWriter

func (self *RenderWriter) GetWrappedWriter() io.Writer

WrappingWriter interface

func (*RenderWriter) Write

func (self *RenderWriter) Write(b []byte) (int, error)

io.Writer interface

type Representation

type Representation struct {
	Construct RepresentionFunc
	Describe  RepresentionFunc
	Present   RepresentionFunc
	Erase     RepresentionFunc
	Modify    RepresentionFunc
	Call      RepresentionFunc
}

func CreateRepresentation

func CreateRepresentation(node *ard.Node, runtime *goja.Runtime) (*Representation, error)

func (*Representation) Handle

func (self *Representation) Handle(context *Context) bool

Handler interface HandleFunc signature

type Representations

type Representations map[string]*Representation

func CreateRepresentations

func CreateRepresentations(config ard.Value, runtime *goja.Runtime) (Representations, error)

type RepresentionFunc

type RepresentionFunc func(context *Context) error

func NewRepresentationFunc

func NewRepresentationFunc(function interface{}, runtime *goja.Runtime) (RepresentionFunc, error)

type Resource

type Resource struct {
	*Router

	Facets []*Facet
}

func NewResource

func NewResource(name string) *Resource

func (*Resource) AddFacet

func (self *Resource) AddFacet(facet *Facet)

type Route

type Route struct {
	Name          string
	PathTemplates PathTemplates
	Handler       HandleFunc
}

func NewRoute

func NewRoute(name string) *Route

func (*Route) Handle

func (self *Route) Handle(context *Context) bool

Handler interface HandleFunc signature

func (*Route) Match

func (self *Route) Match(path string) map[string]string

type Router

type Router struct {
	Name     string
	Handlers []HandleFunc
	Routes   []*Route
}

func NewRouter

func NewRouter(name string) *Router

func (*Router) AddHandler

func (self *Router) AddHandler(handler HandleFunc)

func (*Router) AddRoute

func (self *Router) AddRoute(route *Route)

func (*Router) Handle

func (self *Router) Handle(context *Context) bool

Handler interface HandleFunc signature

type Server

type Server struct {
	Name     string
	Address  string
	Protocol string
	Secure   bool
	Debug    bool
	Handler  HandleFunc
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string) *Server

func (*Server) Handle

func (self *Server) Handle(context *fasthttp.RequestCtx)

fasthttp.RequestHandler signature

func (*Server) Listen

func (self *Server) Listen() (net.Listener, error)

func (*Server) Start

func (self *Server) Start() error

Startable interface

func (*Server) Stop

func (self *Server) Stop() error

Startable interface

type Static

type Static struct {
	RequestHandler fasthttp.RequestHandler
	// contains filtered or unexported fields
}

func NewStatic

func NewStatic(root string, indexes []string) *Static

func (*Static) Close

func (self *Static) Close()

func (*Static) Handle

func (self *Static) Handle(context *Context) bool

Handler interface HandleFunc signature

type WrappingWriter

type WrappingWriter interface {
	io.WriteCloser

	GetWrappedWriter() io.Writer
}

Jump to

Keyboard shortcuts

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