rocket
Rocket is a web framework inspired by rocket-rs.
Install
go get github.com/dannypsnl/rocket
Warning
This library won't take care of API break changes.
Light-weight web framework for Go
Home Page: https://dannypsnl.github.io/rocket/
License: MIT License
Rocket is a web framework inspired by rocket-rs.
go get github.com/dannypsnl/rocket
This library won't take care of API break changes.
As title, if we can handle func(http.ResponseWriter, *http.Request)
, then we can make people easier to move to rocket
.
@shana0440 what do you think
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.
As title, a route can have variant length parameter like: /static/*filepath
already have PR, but for recording.
For example, if rocket would call Valid() bool
after fill user context, then early return HTTP Code 400
@shana0440
// base url + handler url
// "/" + "/"
// Cause:
// index out of range
@shana0440 What if we make route?:queryK
?
We need a builder of response to add some property for our response.
Like content type and more.
Use github_page.
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
After discussion, we decide to use response to write cookie rather than write back to cookies context.
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
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.
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)}
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.
I will find out the reason
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)
Now is 53%, and I hadn't test [http, panic] part.
target is 80%, temporary.
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.
rocket.Ignite(":8080").
Mount("/basic-route", rocket.Routes{ home, ...handlers })
/hello
/hello/:name
static/*path
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.
I think this project doesn't perform well, I want to restart another thing, so close this
As title, should allow the user access request header & also can decide response header.
@shana0440 please improve this list.
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:
Cookies.Get(name string)
Cookies.List()
Cookies.Add(*http.Cookie)
For example
Mount
apply groupAlthough param path is work.
But filepath that way hadn't work now.
Because it need a different way be deal.
https://github.com/gavv/httpexpect >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> httptest
For example
'/date/20' // First
'/date/:date' // Second choose
Create for discussion about how to create middleware
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
The data structure of methods handler caused route matching conflict.
Because we put everything at the same place, that's not correct.
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)
})
That's because I use polling to searching matching route.
So I should sort the array before Launch.
As title should provide a default solution & a custom way to patch it.
as title
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.
As title. Something like this.
rk.Post("/api/user, id", ignore...)
Now Document is almost nothing. So we have to improve it.
As title, in http
, Form also contains query like ?value=1
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
}
}
if the path exists but the method is not correct, should response 403 not 404.
for example
var Hello = rocket.Get("/hello", func() string {
return "hello"
})
var World = rocket.Get("/world", func() string {
return "world"
})
rk.Mount("/test", Hello, World)
the World won't work.
should split to
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)
})
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"])
})
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.