rest

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAccept          = "Accept"
	HeaderAcceptEncoding  = "Accept-Encoding"
	HeaderCacheControl    = "Cache-Control"
	HeaderContentEncoding = "Content-Encoding"
	HeaderContentType     = "Content-Type"
	HeaderETag            = "ETag"
	HeaderIfModifiedSince = "If-Modified-Since"
	HeaderIfNoneMatch     = "If-None-Match"
	HeaderLastModified    = "Last-Modified"
	HeaderLocation        = "Location"
	HeaderPrudenceCached  = "X-Prudence-Cached"
	HeaderServer          = "Server"
)
View Source
const (
	PathVariable    = "__path"
	ParthVariableRe = `(?P<` + PathVariable + `>.*)`
)

Variables

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

Functions

func CreateCookie added in v1.0.3

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

CreateFunc signature

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 GetEncodingType

func GetEncodingType(name string) platform.EncodingType

func Handled

func Handled(context *Context) bool

HandleFunc signature

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 ContentType added in v1.0.3

type ContentType struct {
	Name    string
	Type    string
	SubType string
}

func NewContentType added in v1.0.3

func NewContentType(name string) ContentType

func (ContentType) String added in v1.0.3

func (self ContentType) String() string

fmt.Stringify interface

type ContentTypePreference added in v1.0.3

type ContentTypePreference struct {
	ContentType
	Weight float64
}

func ParseContentTypePreference added in v1.0.3

func ParseContentTypePreference(text string) (ContentTypePreference, error)

func (*ContentTypePreference) Matches added in v1.0.3

func (self *ContentTypePreference) Matches(contentType ContentType, matchWildcard bool) bool

func (ContentTypePreference) String added in v1.0.3

func (self ContentTypePreference) String() string

fmt.Stringify interface

type ContentTypePreferences added in v1.0.3

type ContentTypePreferences []ContentTypePreference

func ParseContentTypePreferences added in v1.0.3

func ParseContentTypePreferences(text string) ContentTypePreferences

func (ContentTypePreferences) Len added in v1.0.3

func (self ContentTypePreferences) Len() int

sort.Interface interface

func (ContentTypePreferences) Less added in v1.0.3

func (self ContentTypePreferences) Less(i int, j int) bool

sort.Interface interface

func (ContentTypePreferences) Swap added in v1.0.3

func (self ContentTypePreferences) Swap(i int, j int)

sort.Interface interface

type Context

type Context struct {
	Request  *Request
	Response *Response

	Log   logging.Logger
	Name  string
	Debug bool

	Path      string
	Variables ard.StringMap

	Done    bool
	Created bool
	Async   bool

	CacheDuration float64 // seconds
	CacheKey      string
	CacheGroups   []string
	// contains filtered or unexported fields
}

func NewContext

func NewContext(responseWriter http.ResponseWriter, request *http.Request) *Context

func (*Context) AddName added in v1.0.3

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

func (*Context) Copy

func (self *Context) Copy() *Context

func (*Context) DeleteCachedRepresentation

func (self *Context) DeleteCachedRepresentation()

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) GetCachedRepresentationBody

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

func (*Context) InternalServerError added in v1.0.3

func (self *Context) InternalServerError(err error)

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) Redirect added in v1.0.3

func (self *Context) Redirect(url string, status int) error

func (*Context) StartCapture

func (self *Context) StartCapture(name string)

func (*Context) StartRender

func (self *Context) StartRender(renderer string, jsContext *js.Context) 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) WriteJson added in v1.0.3

func (self *Context) WriteJson(value ard.Value, indent string) (int, error)

func (*Context) WriteString

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

func (*Context) WriteYaml added in v1.0.3

func (self *Context) WriteYaml(value ard.Value, indent 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 EncodingPreference added in v1.0.3

type EncodingPreference struct {
	Name   string
	Type   platform.EncodingType
	Weight float64
}

func ParseEncodingPreference added in v1.0.3

func ParseEncodingPreference(text string) (EncodingPreference, error)

func (EncodingPreference) String added in v1.0.3

func (self EncodingPreference) String() string

fmt.Stringify interface

type EncodingPreferences added in v1.0.3

type EncodingPreferences []EncodingPreference

func ParseEncodingPreferences added in v1.0.3

func ParseEncodingPreferences(text string) EncodingPreferences

func (EncodingPreferences) Len added in v1.0.3

func (self EncodingPreferences) Len() int

sort.Interface interface

func (EncodingPreferences) Less added in v1.0.3

func (self EncodingPreferences) Less(i int, j int) bool

sort.Interface interface

func (EncodingPreferences) NegotiateBest added in v1.0.3

func (self EncodingPreferences) NegotiateBest(context *Context) platform.EncodingType

func (EncodingPreferences) Swap added in v1.0.3

func (self EncodingPreferences) Swap(i int, j int)

sort.Interface interface

type Facet

type Facet struct {
	*Route

	Representations *Representations
}

func NewFacet

func NewFacet(name string) *Facet

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{}, jsContext *js.Context) (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 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, context *js.Context) (*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, context *js.Context) (*Representation, error)

func (*Representation) Handle

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

Handler interface HandleFunc signature

type RepresentationEntry added in v1.0.3

type RepresentationEntry struct {
	ContentType    ContentType
	Representation *Representation
}

type Representations

type Representations struct {
	Entries []*RepresentationEntry
}

func CreateRepresentations

func CreateRepresentations(config ard.Value, context *js.Context) (*Representations, error)

func (*Representations) Add added in v1.0.3

func (self *Representations) Add(contentType ContentType, representation *Representation)

func (*Representations) NegotiateBest added in v1.0.3

func (self *Representations) NegotiateBest(context *Context) (*Representation, string, bool)

type RepresentionFunc

type RepresentionFunc func(context *Context) error

func NewRepresentationFunc

func NewRepresentationFunc(function interface{}, jsContext *js.Context) (RepresentionFunc, error)

type Request added in v1.0.2

type Request struct {
	Host    string
	Port    int
	Header  http.Header
	Method  string
	Query   url.Values
	Cookies []*http.Cookie
	Body    string

	Direct *http.Request
}

func NewRequest added in v1.0.2

func NewRequest(request *http.Request) *Request

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 Response added in v1.0.2

type Response struct {
	Status      int
	Header      http.Header
	Cookies     []*http.Cookie
	ContentType string
	CharSet     string
	Language    string

	Signature     string
	WeakSignature bool
	Timestamp     time.Time

	Buffer *bytes.Buffer
	Bypass bool
	Direct http.ResponseWriter
}

func NewResponse added in v1.0.2

func NewResponse(responseWriter http.ResponseWriter) *Response

func (*Response) AddCookie added in v1.0.3

func (self *Response) AddCookie(config ard.StringMap) error

func (*Response) Reset added in v1.0.2

func (self *Response) Reset()

type ResponseWriterWrapper added in v1.0.2

type ResponseWriterWrapper struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriterWrapper added in v1.0.2

func NewResponseWriterWrapper(context *Context) *ResponseWriterWrapper

func (*ResponseWriterWrapper) Write added in v1.0.2

func (self *ResponseWriterWrapper) Write(p []byte) (int, error)

func (*ResponseWriterWrapper) WriteHeader added in v1.0.2

func (self *ResponseWriterWrapper) WriteHeader(status int)

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
	Secure      bool
	Certificate string
	Key         string
	NCSAPrefix  string
	Debug       bool
	Handler     HandleFunc
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string) *Server

func (*Server) ServeHTTP added in v1.0.2

func (self *Server) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

http.Handler interface

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 {
	Root string
}

func NewStatic

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

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