Giter Club home page Giter Club logo

rocket's Introduction

rocket's People

Contributors

dannypsnl avatar shana0440 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

Watchers

 avatar  avatar  avatar  avatar

Forkers

shana0440

rocket's Issues

Do route's verification

Like the basic route, you can not write parameter at there.
And /*name can not append anything. Because it's a file-path, everything following will be seems as file-path.

Lack of documentation

Use github_page.

  • quick start
  • documents
    • server
    • handler
    • user-defined context
    • response
    • header
    • cookie

can't handle the url endwith "/"

if the URL is /hello/, the handler will panic

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/dannypsnl/rocket.handlerByMethod(0xc420
055f40, 0x13272c0, 0x13b5fd8, 0x139f095, 0x4, 0xc4
2012a180)
        /Users/daniel/Code/src/github.com/dannypsn
l/rocket/handler.go:118 +0x88f
github.com/dannypsnl/rocket.Post(0x139f558, 0x6, 0
x13272c0, 0x13b5fd8, 0xc42012a180)
        /Users/daniel/Code/src/github.com/dannypsn
l/rocket/handler_creator.go:10 +0x54

[Feature]set header via different response type

For example:

var hello = rocket.Get("/:name/age/:age", func(user *User) string {
	return fmt.Sprintf("Hello %s, your age is %d\n", user.Name, user.Age)
})

This return Content-Type: text/plain

var page = rocket.Get("/", func() rocket.Html {
  return `
<h1>
  Title
</h1>
Hello
`
})

Will return Content-Type: text/html

[Feature] Fairing

A fairing is some rules would be triggered on some timer.
The fairing will own some handlers, so these handlers life cycle would be controlled by this fairing.

  • OnResponse
  • OnRequest

[Bug] if route has root route, will emit route into ""

code:

var noParamNoRoute = rocket.Get("/", func() string {
	return "no param no route"
})
// Mount("/test", noParamNoRoute)

output:

&url.Error{Op:"Get", URL:"http://127.0.0.1:60241/test", Err:(*errors.errorString)(0xc420010050)}

[Bug] Context order can cause panic

When we have a handler function type is func(cookies *rocket.Cookie, header *rocket.Header) string, everything is ok, but when we use func(header *rocket.Header, cookies *rocket.Cookie) string, it will panic, because we use append into context to handle this part.

Optional field

The handler should return HTTP Code 400 if can't fill user-defined context, but if a field is a pointer, that means the field is omittable(but if it is a type error, still have to return 400)

Can't mount repeated route

Matching rule should be smarter.
It should match route only when route is totally could.
Example

// ...
Mount("/", index).
Mount("/", static).
Launch()

static have one parameter, so only we have parameter then we match static.

Benchmark performance for some example

  • return a string without user-defined context for a pure route, e.g. /hello
  • return a string with user-defined context for variant route, e.g. /hello/:name
    - [ ] reply file for path route, e.g. static/*path
    - [ ] return a HTML
    - [ ] return a JSON
  • receive JSON request

[Feature]Support decode JSON body

For example:

type User struct {
    Name string `json:"name"`
}

var j = rocket.Post("/user", func(u *User) string {
})

No need to type any key name in route. Rocket will just try to decode json into entry type.

[Feature]Get Cookie context to handle it

As the title might add a tag like cookie:"key", and type must be map[string]string

After discussion, I think the better way is creating a type in rocket call Cookies,
so if the user's handler function has a parameter is rocket.Cookies, we fill it with our cookies.

e.g.

func(ck *rocket.Cookies) {}

Then the user can modify the cookies whatever they wanted.

TODOs:

  • read cookie by name Cookies.Get(name string)
  • read all cookies Cookies.List()
  • create new cookie Cookies.Add(*http.Cookie)
  • remove exist cookie(this operation should return error)
  • modify cookie content

Dynamic Routing

Although param path is work.
But filepath that way hadn't work now.
Because it need a different way be deal.

Next release: v0.13.0

  • cookies write
  • MIME type solution: #41 complete
  • Fairing: #134 complete
    • On response
    • On request
    • On launch
  • Guard
  • streaming

Remove form parameter in route

Since we don't have to change route string & still can know what form key we needed, there has no reason to change route string.

e.g.

Not /route,form_value but /route only

Place of Methods handler

The data structure of methods handler caused route matching conflict.
Because we put everything at the same place, that's not correct.

Support others type for context field

e.g.

type User struct {
    Name string `route:"name"`
    Age uint32 `route:"age"`
}

var hello = rk.Get("/:name/:age", func(u *User) string {
    return fmt.Sprintf("user<name: %s, age: %d>", u.Name, u.Age)
})

[Doc] Explain why using user-defined context

This issue is because by default using user-defined context just caused complex in the program, but it would be good when we want to validate the same thing at several different handlers.

So we should have some docs to explain how to create advanced user-defined context.

Improve performance of Route by add cache layer

It would be great to add a field in Router is variantRoute for any :variantRote

for route, _ := range next {
    if isParameter(route) {
        useToMatch = append(useToMatch, route)
        i++
        if i != len(rs) {
            next = next[route].Children
        }
        break
    }
}

403 method not allow

if the path exists but the method is not correct, should response 403 not 404.

[Refactor]server tests

should split to

  • HTTP method part
  • response type part
  • response content part
  • route matching part

Use tag struct

Example:

type User struct {
    Id int `query:"id"`
    Name string `param:"name"`
}

var userPage = rocket.Get("/user/:id", func(user *User) string {
    return fmt.Sprintf("User<%d>, name: %s", user.Id, user.Name)
})
  • can use the variant in route string.
  • can load the variant automatically & correctly.

Use function instead of struct

Now user had to use Handler to create a handler for rocket.
Maybe can do some like:

var hello = rocket.Get("/name/:name/age/:age", func(ctx rocket.Context) string {
    return fmt.Sprintf("Hello, %s.\nYour age is %s", ctx["name"], ctx["age"])
})

static file mime type

A common way about using a variant route is for static files in the project.
Then how to decide file's mime type would be an important issue.

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.