func (rh *RootHandler) convertRequestResponse(w http.ResponseWriter, r *http.Request, endpoint rest.ServerResource) (*rest.Request, *rest.Response) { request := rest.NewRequest(r, rest.NewRequestContext(), endpoint) response := &rest.Response{ Status: 200, Message: "ok", Headers: make(map[string]string), } return request, response }
package rest_test import ( "github.com/gotgo/resti/rest" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("RequestContext", func() { It("should add get remove", func() { ctx := rest.NewRequestContext() ctx.Add("a", "data", 37) result, found := ctx.Get("a", "data") Expect(found).To(BeTrue()) Expect(result).To(Equal(37)) result, found = ctx.Get("b", "data") Expect(found).To(BeFalse()) ctx.Remove("a", "data") result, found = ctx.Get("b", "data") Expect(found).To(BeFalse()) }) })
var ( client *rest.Client context *rest.RequestContext ) BeforeEach(func() { endpoint := &rest.ResourceEndpoint{ Host: "localhost:23000", Scheme: "http", } client = &rest.Client{ Endpoints: []*rest.ResourceEndpoint{endpoint}, } context = rest.NewRequestContext() }) Context("Client DO", func() { AssertDoExpectations := func(req *rest.ClientRequest) { resp, err := client.Send(req, context) hr := resp.HttpResponse Expect(hr.StatusCode).To(Equal(200)) Expect(err).To(BeNil()) Expect(resp).ToNot(BeNil()) bytes, err := resp.Bytes() Expect(err).To(BeNil())