andeya / faygo

Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.

Home Page:https://github.com/henrylee2cn/faydoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

url with trailing slash /index/100/ match route "/index/:id" return 301 not 404

tablecell opened this issue · comments

package main

import (
	"github.com/henrylee2cn/faygo"
	"time"
)

type Index struct {
}

func (i *Index) Serve(ctx *faygo.Context) error {
	if ctx.CookieParam("faygoID") == "" {
		ctx.SetCookie("faygoID", time.Now().String())
	}
	return ctx.JSON(200, i)
}

func main() {
	app := faygo.New("myapp", "0.1")
	app.GET("/index/:id", new(Index))
	faygo.Run() //8080
}
```
$ curl   http://localhost:8080/index/100/
<a href="/index/100">Moved Permanently</a>.

```
package main
import (
    "fmt"
    "net/http"
)
func main() {
    http.HandleFunc("/hello/aa", func (w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Welcome to my website!")
    })
   http.ListenAndServe(":80", nil)
}

```
$ curl   http://localhost:8080/index/100/
404 page not found