Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for httprouter? #2

Open
matthewmueller opened this issue Jan 3, 2017 · 0 comments
Open

Support for httprouter? #2

matthewmueller opened this issue Jan 3, 2017 · 0 comments

Comments

@matthewmueller
Copy link

Hi there, thanks for putting this library together. I was wondering if it had support for https://github.com/julienschmidt/httprouter?

I tried getting it working, but keep getting 404 not found (works with mux):

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"

	"github.com/apex/go-apex"
	"github.com/fujiwara/ridge"
	"github.com/julienschmidt/httprouter"
)

var router = httprouter.New()

func init() {
	router.GET("/", handleRoot)
	router.GET("/hello", handleHello)
}

func main() {
	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		r, err := ridge.NewRequest(event)
		if err != nil {
			log.Println(err)
			return nil, err
		}
		w := ridge.NewResponseWriter()
		router.ServeHTTP(w, r)
		return w.Response(), nil
	})
}

func handleHello(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	w.Header().Set("Content-Type", "text/plain")
	fmt.Fprintf(w, "Hello %s\n", r.FormValue("name"))
}

func handleRoot(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	w.Header().Set("Content-Type", "text/plain")
	fmt.Fprintln(w, "Hello World")
	fmt.Fprintln(w, r.URL)
}

Any help would be appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant