goaeoas

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: GPL-3.0 Imports: 23 Imported by: 6

README

goaeoas

Documentation

Index

Constants

View Source
const (
	DateTimeInputFormat = "2006-01-02T15:04"
)

Variables

View Source
var (

	// DefaultScheme is used to construct URLs, not to match them, since App Engine forwards HTTPS requests as HTTP requests.
	DefaultScheme    = "http"
	CORSAllowHeaders = []string{"Content-Type", "Accept", "Authorization"}
)

Functions

func AddFilter

func AddFilter(f func(ResponseWriter, Request) (bool, error))

Filters are run before the request handlers, and any filter returning false or an error will stop the handler from running. Returned errors will get forwarded to the client.

func AddPostProc

func AddPostProc(f func(ResponseWriter, Request, error) (bool, error))

PostProcs are run in sequence after the request handler. The first proc receives the error returned by the handler, and all consecutive procs get the error returned by the previous proc. Any proc returning false will stop further procs from running. The final returned error will be forwarded to the client.

func CORSHeaders

func CORSHeaders(w http.ResponseWriter)

func Copy

func Copy(dest interface{}, r Request, method string) error

func CopyBytes

func CopyBytes(dest interface{}, r Request, b []byte, method string) error

func DumpJava

func DumpJava(dir string, classes map[string]string) error

func GenerateJava

func GenerateJava(pkg string) (map[string]string, error)

func HTTPError

func HTTPError(w http.ResponseWriter, r *http.Request, err error)

func Handle

func Handle(ro *mux.Router, pattern string, methods []string, routeName string, f func(ResponseWriter, Request) error)

func HandleError

func HandleError(w http.ResponseWriter, r Request, err error)

func HandleResource

func HandleResource(ro *mux.Router, re *Resource)

func HeadCallback

func HeadCallback(f func(*Node) error)

func Media

func Media(r *http.Request, header string) (media, charset string)

func SetJSONFormURL

func SetJSONFormURL(u *url.URL)

func SetJSVURL

func SetJSVURL(u *url.URL)

func VersionETagCache added in v0.1.5

func VersionETagCache(handler func(ResponseWriter, Request) error) func(ResponseWriter, Request) error

Types

type Content

type Content interface {
	HTMLNode() (*Node, error)
}

type DocField

type DocField struct {
	Name string
	Type *DocType
	// contains filtered or unexported fields
}

func NewDocFields

func NewDocFields(typ reflect.Type, method string) ([]DocField, error)

func (DocField) ToJSONSchema

func (d DocField) ToJSONSchema() (*JSONSchema, error)

type DocType

type DocType struct {
	Kind   string
	Name   string
	Elem   *DocType
	Fields []DocField
	// contains filtered or unexported fields
}

func NewDocType

func NewDocType(typ reflect.Type, method string) (*DocType, error)

func (DocType) GetField

func (d DocType) GetField(n string) (*DocField, bool)

func (DocType) ToJSONSchema

func (d DocType) ToJSONSchema() (*JSONSchema, error)

func (DocType) ToJavaClasses

func (d DocType) ToJavaClasses(pkg, meth string) (map[string]string, error)

type HTTPErr

type HTTPErr struct {
	Body   string
	Status int
}

func (HTTPErr) Error

func (h HTTPErr) Error() string

type Item

type Item struct {
	Properties interface{}
	Name       string
	Desc       [][]string
	Links      Links
}

func NewItem

func NewItem(i interface{}) *Item
func (i *Item) AddLink(l Link) *Item

func (Item) HTMLNode

func (i Item) HTMLNode() (*Node, error)

func (Item) MarshalJSON

func (i Item) MarshalJSON() ([]byte, error)

func (*Item) SetDesc

func (i *Item) SetDesc(s [][]string) *Item

func (*Item) SetName

func (i *Item) SetName(s string) *Item

type Itemer

type Itemer interface {
	Item(Request) *Item
}

type JSONSchema

type JSONSchema struct {
	Type                 string                `json:"type"`
	Properties           map[string]JSONSchema `json:"properties,omitempty"`
	AdditionalProperties *JSONSchema           `json:"additionalProperties,omitempty"`
	Items                *JSONSchema           `json:"items,omitempty"`
	Title                string                `json:"title,omitempty"`
}
type Link struct {
	Rel         string
	Route       string
	URL         string
	RouteParams []string
	QueryParams url.Values
	Method      string
	Type        reflect.Type
	Render      bool
	// contains filtered or unexported fields
}

func (*Link) HTMLNode

func (l *Link) HTMLNode() (*Node, error)

func (Link) MarshalJSON

func (l Link) MarshalJSON() ([]byte, error)

func (*Link) Resolve

func (l *Link) Resolve() (string, error)

type LinkDecorator

type LinkDecorator func(*Link, *url.URL) error
type Links []Link

func (Links) Len

func (l Links) Len() int

func (Links) Less

func (l Links) Less(i, j int) bool

func (Links) Swap

func (l Links) Swap(i, j int)

type List

type List []Content

type Lister

type Lister struct {
	Path    string
	Route   string
	Handler func(ResponseWriter, Request) error
	// QueryParams document the query params this lister handles, and are only used when generating code or documentation.
	QueryParams []string
}

type Method

type Method int
const (
	Create Method = iota
	Update
	Delete
	Load
)

func (Method) HTTPMethod

func (m Method) HTTPMethod() string

func (Method) String

func (m Method) String() string

type Node

type Node struct {
	*html.Node
}

func NewEl

func NewEl(s string, attrs ...string) *Node

func (*Node) AddEl

func (n *Node) AddEl(s string, attrs ...string) *Node

func (*Node) AddNode

func (n *Node) AddNode(node *Node) *Node

func (*Node) AddRaw

func (n *Node) AddRaw(b []byte) (*Node, error)

func (*Node) AddText

func (n *Node) AddText(s string) *Node

func (*Node) Render

func (n *Node) Render(w io.Writer) error

func (*Node) String

func (n *Node) String() string

type Properties

type Properties interface{}

type Request

type Request interface {
	Req() *http.Request
	Vars() map[string]string
	NewLink(Link) Link
	Values() map[string]interface{}
	DecorateLinks(LinkDecorator)
	Media() string
}

type Resource

type Resource struct {
	Create  interface{}
	Update  interface{}
	Delete  interface{}
	Load    interface{}
	Listers []Lister

	FullPath   string
	CreatePath string

	Type        reflect.Type
	RenderLinks bool
}
func (r *Resource) Link(rel string, meth Method, routeParams []string) Link

func (*Resource) Route

func (r *Resource) Route(meth Method) string

func (*Resource) URL

func (r *Resource) URL(meth Method, id interface{}) (*url.URL, error)

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	SetContent(Content)
}

Jump to

Keyboard shortcuts

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