rest

package module
v0.0.0-...-559cfa5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2018 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultServeMux = New()

DefaultServeMux is the default ServeMux.

Functions

func Handle

func Handle(path string, v interface{}, options ...RestFunc)

Handle registers the handler for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.

func NewStatusError

func NewStatusError(err string, statusCode int) error

Types

type Deleter

type Deleter interface {
	Delete(ctx context.Context) (interface{}, error)
}

type Getter

type Getter interface {
	Get(ctx context.Context) (interface{}, error)
}

type Poster

type Poster interface {
	Post(ctx context.Context) (interface{}, error)
}

type Putter

type Putter interface {
	Put(ctx context.Context) (interface{}, error)
}

type RestFunc

type RestFunc func(context.Context, *http.Request) (context.Context, error)

RestFunc type is an adapter to allow the use of ordinary functions as REST middleware handlers. If f is a function with the appropriate signature, RestFunc(f) is a Handler object that calls f.

type ServeMux

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

func New

func New(options ...RestFunc) *ServeMux

func (*ServeMux) Handle

func (mux *ServeMux) Handle(path string, v interface{}, options ...RestFunc)
Example
package main

import "golang.org/x/net/context"

type HelloReq struct {
	Name string `rest:"name,path"`
}

func (h *HelloReq) Get(ctx context.Context) (interface{}, error) {
	return "Hello " + h.Name, nil
}

func main() {
	mux := New()
	mux.Handle("/:name", new(HelloReq))
}
Output:

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, req *http.Request)

type StatusError

type StatusError struct {
	Err        string `json:"message"`
	StatusCode int    `json:"statusCode"`
}

func (StatusError) Error

func (h StatusError) Error() string

Jump to

Keyboard shortcuts

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