buaazp / fasthttprouter

A high performance fasthttp request router that scales well
http://godoc.org/github.com/buaazp/fasthttprouter
BSD 3-Clause "New" or "Revised" License
872 stars 91 forks source link

Is the example working? #17

Closed kokizzu closed 7 years ago

kokizzu commented 7 years ago

I've tried the example from the README.md:

package main

import (
        "fmt"
        "log"

        "github.com/buaazp/fasthttprouter"
        "github.com/valyala/fasthttp"
)

func Index(ctx *fasthttp.RequestCtx) {
        fmt.Fprint(ctx, "Welcome!\n")
}

func Hello(ctx *fasthttp.RequestCtx) {
        fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}

func main() {
        router := fasthttprouter.New()
        router.GET("/", Index)
        router.GET("/hello/:name", Hello)

        log.Fatal(fasthttp.ListenAndServe(":8080", router.Handler))
}

When I run it, it shows:

./test.go:21: cannot use Index (type func(*fasthttp.RequestCtx)) as type fasthttprouter.Handle in argument to router.GET
./test.go:22: cannot use Hello (type func(*fasthttp.RequestCtx)) as type fasthttprouter.Handle in argument to router.GET
razonyang commented 7 years ago

I guess that you are using the old version, please try the newest package.

kokizzu commented 7 years ago

Ah you're right, I didn't notice..

$ go get -u -v github.com/buaazp/fasthttprouter
github.com/buaazp/fasthttprouter (download)
# cd /home/asd/go/src/github.com/buaazp/fasthttprouter; git pull --ff-only
fatal: Not possible to fast-forward, aborting.
package github.com/buaazp/fasthttprouter: exit status 128