tollbooth_gorestful

package
v0.0.0-...-c0d78fd Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2016 License: MIT Imports: 3 Imported by: 0

README

tollbooth_gorestful

Middleware for go-restful

Import package thirdparty/tollbooth_gorestful and use tollbooth_gorestful.LimitHandler to which your own handler can be passed

Five Minutes Tutorial


package resources

import (
	"github.com/didip/tollbooth"
	"github.com/didip/tollbooth/thirdparty/tollbooth_gorestful"
	"github.com/emicklei/go-restful"
)

type User struct {
  ID                string  `json:"id"`
	Email             string  `json:"email"`
}

func (u *User) Register(container *restful.Container) {
	ws := new(restful.WebService)
	ws.
		Path("/users").
		Doc("Manage Users").
		Consumes(restful.MIME_JSON).
		Produces(restful.MIME_JSON)


	ws.Route(ws.GET("/{id}").To(tollbooth_gorestful.LimitHandler(u.GetUser, tollbooth.NewLimiter(3, time.Minute))).
		// docs
		Doc("get a user").
		Operation("GetUser").
		Param(ws.PathParameter("id", "identifier of the user").DataType("string")).
		Writes(User{}))

	container.Add(ws)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitHandler

func LimitHandler(handler restful.RouteFunction, limiter *config.Limiter) restful.RouteFunction

Types

This section is empty.

Jump to

Keyboard shortcuts

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