go-martini / martini Goto Github PK
View Code? Open in Web Editor NEWClassy web framework for Go
Home Page: martini.codegangsta.io
License: MIT License
Classy web framework for Go
Home Page: martini.codegangsta.io
License: MIT License
There should be a super easy default setup for martini. I like to call it classic
Hi,
How can i add a middle layer for serving gzip files? It is to reduce file size while serving static content.
I probably not understand how Next() works. I wanted to create middleware which creates MongoDB connection dedicated to particular http request so I have to defer connection.Close(). How can I do that?
Finally I stripped my code to almost nothing and this is my result:
func main() {
middleware := func(c martini.Context) {
defer println(4)
println(1)
c.Next()
println(3)
}
m := martini.Classic()
m.Get("/test", middleware, func() {
println(2)
}
m.Run()
}
[martini] listening on port 3000
[martini] Started GET /test
[martini] Completed 0 in 145.732us
1
3
4
2
quick question,
is the gh-pages branch supposed to be MIT licensed too?
thanks
Create a introductory video tour to have on the landing page
The basic concept is that we wan't to be able to rewrite a response if we so please. The default http.ResponseWriter implementation does not handle multiple writes very well, so we should wrap the default implementation into one that defers the actual writing of the response until Commit()
is called.
similar to express.js
package main
import "github.com/codegangsta/martini"
func main() {
m := martini.Classic()
m.Get("/", func() string {
return "Hello world!"
})
m.Run()
}
Building, running and then browsing :3000 initiates a download of the built executable (5.3MB). Changing the path to '/test' and browsing :3000/test will return "Hello world!". This is on OSX Mavericks and tested with Go 1.1 and Go 1.2.
Running the default net/http server example on :3000 work just fine.
This is pretty bizarre behavior. Have you seen it before?
go get github.com/codegangsta/martini
github.com/codegangsta/martini
Dropbox/go/src/github.com/codegangsta/martini/martini.go:94: method r.Handle is not an expression, must be called
Dropbox/go/src/github.com/codegangsta/martini/router.go:58: method route.handle is not an expression, must be called
The last commit was 3302320
If a handler returns something, Martini will write the result to the current *http.Request as a string
I think you meant http.ResponseWriter
I got bit by this. It is unlikely that someone will check it an error when calling use. Panic makes sense in this kind of situation
I like this syntax better
m := martini.Classic()
m.Use(martini.Recover)
m.Use(martini.Logging)
m.Run()
martini.New() creates it's own logger. It would be nice to be able to initialize Martini with a custom logger.
copy from connect http://www.senchalabs.org/connect/favicon.html
The Martini router may wish to provide a way to enforce trailing slashes and add them when not present (and vice-versa) so that /stuff/abc-def
can be re-directed to /stuff/abc-def/
.
Users could set this with a boolean when creating a new Martini instance.
Could you put some benchmarking on README?
I need some help with json. I would like to write middleware and be able to create handlers like these:
func jsonHandler() *MyTypeMarshallableToJson {
return &MyTypeMarshallableToJson{}
}
func jsonWithStatusHandler() (int, *MyTypeMarshallableToJson) {
return 201, &MyTypeMarshallableToJson{}
}
It would be awesome if I could delegate json/xml formatting to middlewares and only return domain objects in handlers.
Is it even possible? Can I have access to handler's "return"? Maybe Is there another more idiomatic approach?
we don't want people muddling around with public directories. Make sure the static handler is secure in this way.
add a handler to pull html pages (from public?) to handle specific error codes
There are really not a lot of them so this should be really easy to do
trying to add regexp pattern matching to route like the gorilla mux route, any help
I was installing martini with go get
and this showed up:
/usr/lib/go/src/pkg/github.com/mvader/martini/martini.go:94: method r.Handle is not an expression, must be called
/usr/lib/go/src/pkg/github.com/mvader/martini/router.go:58: method route.handle is not an expression, must be called
I took a look at the code but it looked good to me.
Go version: go version go1.1.2 linux/386
Hi
First of all, nice project. I like it a lot.
Some feature that would make this project even more attractive is support for swagger.
Swagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services.
Website: https://developers.helloreverb.com/swagger/
Example: http://petstore.swagger.wordnik.com/
Swagger is already supported by play-framework, scalatra, django, go-restful.
BR, Rene
I'm getting the following error when I try to go get github.com/codegangsta/martini
# github.com/codegangsta/martini
/usr/lib/go/src/pkg/github.com/codegangsta/martini/martini.go:94: method r.Handle is not an expression, must be called
/usr/lib/go/src/pkg/github.com/codegangsta/martini/router.go:58: method route.handle is not an expression, must be called
I'm new to Go so maybe I'm missing something really obvious...
Thanks!
if a route handler returns a (int, interface{})
then we should write out the status code as well as the message.
m.Get("/", func() (int, string) {
return 404, "Not found"
})
Small issue but adds to elegance and convenience
The router throws a 404 when no match is found, make sure that there is status text for easier debugging
It would be nice to have a middleware that parsed url params and provide a martini.Params
service that other middlewares/actions can use
Reproduce by serving martini.Classic()
and putting an index.html
file in the public
directory. Browse http://{host}:{port}/
.
Expected martini to serve index.html
.
Actually returns an HTTP 404
.
Resolve: In static.go
(line 29), dir.Open(file)
fails as file
contains an invalid path: \index.html
. Replacing back-slashes with slashes makes it work as expected. This will probably fail on Linux machines, though (right?).
The form handler should take a pointer to a struct and attempt to bind PostFormFields to the struct. We can use field tags to do some fancy conversion and presence validation. The handler will then inject the struct into any later handlers.
I imagine it looking something like this:
import "github.com/codegangsta/martini/form"
type BlogPost struct {
Title string `form:"title,required"`
Content string `form:"content,required"`
Author string `form:"author"`
}
m.Post("/blogpost", form.Form(&BlogPost), func(p *BlogPost) string {
return p.Content
})
I'm quite new to Go, so please excuse me if this is just nonesense.
Would it be possible for your responseWriter type to implement http.Hijack? This would allow libraries like this websockets one to work with martini.
I'm not sure if this is something that should be done, I was just trying to write something really quick, came up with an error and found out this was the reason. If this is a silly way to do it feel free to tell me ๐
This can be useful to organize your own list of middlewares.
we need a basic static handler
from @davecheney
You can probbaly use a build tag to create a file, something like
// +build !go1.1
func MartiniDoesNotSupportGo1Point0() {
var you_need_go_1_1_or_better = 1 // compile error
}
Is there a way to set those? I can't find anything in the code to suggest it, but I'm still fairly new to go
The basic idea is that martini.Context
will have a set of helper functions that will allow for some convenience to be added.
Martini is great!
I'm just missing the ability to set my own "page not found"-handler if no route matches. That would be great, m'kay.
Cheers :)
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.