Giter VIP home page Giter VIP logo

lion's People

Contributors

akagi201 avatar celrenheit avatar ttacon avatar vrischmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lion's Issues

Mount bug fix


func main() {
	l := lion.New(middleware.Classic())

	sub := lion.New()
	//normal return
	sub.GET("/", func(ctx lion.Context) {
		ctx.Write([]byte("/"))
	})

	//404 page not found ?
	sub.GET("/a", func(ctx lion.Context) {
		ctx.Write([]byte("a"))
	})
	//normal return
	sub.GET("/b", func(ctx lion.Context) {
		ctx.Write([]byte("b"))
	})

	//404 page not found ?
	sub.GET("/c", func(ctx lion.Context) {
		ctx.Write([]byte("c"))
	})
	//normal return
	sub.GET("/d", func(ctx lion.Context) {
		ctx.Write([]byte("d"))
	})

	l.Mount("/api", sub)

	l.Run()
}

@celrenheit

Multiple resource types

Currently there is only one form of resources (RESTful).
This is a small proposal to extend resource to multiple type.

RESTful

router.Resource("/users", myResource)
HTTP method Path Struct's method name
GET /users Get
Head /users Head
POST /users Post
PUT /users Put
PATCH /users Patch
DELETE /users Delete
CONNECT /users Connect

Resourceful

router.Resource("/users", myResource)
HTTP method Path Struct's method name
GET /users Index
POST /users Create
GET /users/:id Show
PUT or PATCH /users/:id Update
DELETE /users/:id Destroy

Hopefully this could be customized.
I currently have not decided the best way to specify differents types.
The resource could implement an interface or by embedding a type.

Feedback are welcome

router fails for named param routes

Just an FYI,

if you have defined the routes:
GET /hello/contact/named => handler1
GET /hello/contact/:dest => handler2

and then do a request..
GET /hello/contact/nameddd it would be expected that the route would match /hello/contact/:dest with the param nameddd, but instead, it returns a 404. This problem grows as you try to compose subrouters.

btw, this does work in the current version of http://github.com/pressly/chi but unfortunately uses recursion which means it uses a few more stack frames for finding the route. I am in the process of updating the tree findNode() method in chi to use a trampoline function and removing the recursive calls.

compare your method https://github.com/celrenheit/lion/blob/master/tree.go#L138-L209 to https://github.com/pressly/chi/blob/master/tree.go#L181-L253

label: question Serving static files

@celrenheit What would be the simplest form to serve static files with Lion? I'm attempting to get the following folders "css", "js", "img", and "templates" all within a root folder named "public".
for _, dir := range []string{"js", "css", "img", "templates"} { lion.ServeFiles(fmt.Sprintf("/%s/", dir)) }

Bug on URL param's

In following code, I'm found some problens on parameters:

package main

import (
    "fmt"
    "net/http"

    "github.com/celrenheit/lion"
    "golang.org/x/net/context"
)

func Handler(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "DNS")
    fmt.Fprintf(w, "DNS: "+dns)
}

func Handler2(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "Anything")
    dnsDiscography := lion.Param(c, "DNSDiscography")

    fmt.Fprintf(w, "DNS: "+dns+" DNSDiscography: "+dnsDiscography)
}

func Handler3(c context.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "I'm here!")
}

func main() {
    l := lion.Classic()
    l.GetFunc("/artistas/:Anything/discografia/:DNSDiscography/", Handler2)
    l.GetFunc("/artistas/:DNS/", Handler)
    l.GetFunc("/artistas/", Handler3)
    l.Run()
}

Results:

$ curl http://localhost:3000/artistas/test/
DNS:

$ curl http://localhost:3000/artistas/test/discografia/testing/
DNS: test DNSDiscography: testing

If I change Handler to get "Anything" param without change the route, it's get "DNS" from route. Following code and resutls:

package main

import (
    "fmt"
    "net/http"

    "github.com/celrenheit/lion"
    "golang.org/x/net/context"
)

func Handler(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "Anything")
    fmt.Fprintf(w, "DNS: "+dns)
}

func Handler2(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "Anything")
    dnsDiscography := lion.Param(c, "DNSDiscography")

    fmt.Fprintf(w, "DNS: "+dns+" DNSDiscography: "+dnsDiscography)
}

func Handler3(c context.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "I'm here!")
}

func main() {
    l := lion.Classic()
    l.GetFunc("/artistas/:Anything/discografia/:DNSDiscography/", Handler2)
    l.GetFunc("/artistas/:DNS/", Handler)
    l.GetFunc("/artistas/", Handler3)
    l.Run()
}

Results:

$ curl http://localhost:3000/artistas/test/
DNS: test

$ curl http://localhost:3000/artistas/test/discografia/testing/
DNS: test DNSDiscography: testing

I not sure about it, but I thing which /artistas/:Anything/... is match before /artistas/:DNS/ and :Anything overwrite :DNS param.

If I switch positions of url's, I found this results:

package main

import (
    "fmt"
    "net/http"

    "github.com/celrenheit/lion"
    "golang.org/x/net/context"
)

func Handler(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "DNS")
    fmt.Fprintf(w, "DNS: "+dns)
}

func Handler2(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "Anything")
    dnsDiscography := lion.Param(c, "DNSDiscography")

    fmt.Fprintf(w, "DNS: "+dns+" DNSDiscography: "+dnsDiscography)
}

func Handler3(c context.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "I'm here!")
}

func main() {
    l := lion.Classic()
    l.GetFunc("/artistas/:DNS/", Handler)
    l.GetFunc("/artistas/:Anything/discografia/:DNSDiscography/", Handler2)
    l.GetFunc("/artistas/", Handler3)
    l.Run()
}

Results:

$ curl http://localhost:3000/artistas/test/
DNS: test

$ curl http://localhost:3000/artistas/test/discografia/testing/
DNS:  DNSDiscography: testing

In this case, if I try to get DNS on Handler2 it's get "Anything" from url. Bellow code and results:

package main

import (
    "fmt"
    "net/http"

    "github.com/celrenheit/lion"
    "golang.org/x/net/context"
)

func Handler(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "DNS")
    fmt.Fprintf(w, "DNS: "+dns)
}

func Handler2(c context.Context, w http.ResponseWriter, r *http.Request) {
    dns := lion.Param(c, "DNS")
    dnsDiscography := lion.Param(c, "DNSDiscography")

    fmt.Fprintf(w, "DNS: "+dns+" DNSDiscography: "+dnsDiscography)
}

func Handler3(c context.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "I'm here!")
}

func main() {
    l := lion.Classic()
    l.GetFunc("/artistas/:DNS/", Handler)
    l.GetFunc("/artistas/:Anything/discografia/:DNSDiscography/", Handler2)
    l.GetFunc("/artistas/", Handler3)
    l.Run()
}
$ curl http://localhost:3000/artistas/test/
DNS: test

$ curl http://localhost:3000/artistas/test/discografia/testing/
DNS: test DNSDiscography: testing

"color" dependancy

go get github.com/celrenheit/lion
# github.com/celrenheit/lion
../../celrenheit/lion/middlewares.go:20: undefined: color.FgHiMagenta
../../celrenheit/lion/middlewares.go:24: undefined: color.FgHiBlue
../../celrenheit/lion/middlewares.go:25: undefined: color.FgHiGreen

might want to vendor, or add to the docs

Contextual rendering

Implementation of a contextual renderer:

  • Render JSON
  • Render XML
  • Render String
  • Render File
  • Attachment
  • Redirect

I would like your feedback on what is your preferred way of handling responses and status codes.

Currently, it works like this (1):

func render(c Context) {
	c.WithStatus(http.StatusOK).
		JSON(data)
}

But I might consider the following way (2):

func render(c Context) {
	c.JSON(http.StatusOK, data)
}

Please, add a comment to this issue with "1" for the first or "2" for the second.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.