Beispiel #1
0
//FormParser parse the url query variables and Body of a request.
//If parsing is succesful then the data can be retrieved via pelau.Request.Get()
func FormParser(req pelau.Request, res pelau.Response, ctx *pelau.Context) {

	req.Raw(func(modReq *pelau.ModifiedRequest) {

		err := modReq.ParseForm()

		if err != nil {

			req.Error(err, nil)

		}

		ctx.Next(req, res, ctx)

	})

}
Beispiel #2
0
//JSONOutput adds JSON encoding support to the Response object.
func JSONOutput(req pelau.Request, res pelau.Response, ctx *pelau.Context) {

	ctx.Next(req, &JSONResponse{res}, ctx)

}
Beispiel #3
0
//JSONInput adds JSON encoding support to the Response object.
func JSONInput(req pelau.Request, res pelau.Response, ctx *pelau.Context) {

	ctx.Next(&JSONRequest{req}, res, ctx)

}
package pelau_test

import (
	"code.google.com/p/gomock/gomock"
	. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/thirdparty/gomocktestreporter"
	. "github.com/onsi/gomega"
	"github.com/quenktech/pelau"
)

var _ = Describe("Context", func() {

	var (
		req     pelau.Request
		res     pelau.Response
		ctx     *pelau.Context
		mockCtl *gomock.Controller
	)

	BeforeEach(func() {
		mockCtl = gomock.NewController(gomocktestreporter.New())
		req = pelau.NewMockRequest(mockCtl)
		res = pelau.NewMockResponse(mockCtl)
		ctx = pelau.DefaultContext()

	})

	It("should call the middleware functions", func() {

		var a, b, c string