https://github.com/k-phoen/negotiate
[DEPRECATED] Martini handler providing content negotiation to requests
https://github.com/k-phoen/negotiate
Last synced: 7 months ago
JSON representation
[DEPRECATED] Martini handler providing content negotiation to requests
- Host: GitHub
- URL: https://github.com/k-phoen/negotiate
- Owner: K-Phoen
- License: mit
- Created: 2014-06-10T03:12:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-05-29T19:10:37.000Z (over 9 years ago)
- Last Synced: 2024-05-01T20:13:00.666Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
negotiate
=========Content negotiation middleware for Martini.
It's a simple wrapper to the [negotiation library](https://github.com/K-Phoen/negotiation) and
[martini-contrib/encoder](https://github.com/martini-contrib/encoder) service.## Status
This project is **DEPRECATED** and should NOT be used.
If someone magically appears and wants to maintain this project, I'll gladly give access to this repository.
## Usage
Here is a ready to use example:
```go
package mainimport (
"github.com/K-Phoen/negotiate"
"github.com/go-martini/martini"
"github.com/martini-contrib/encoder"
"log"
"net/http"
)type Some struct {
Login string `json:"login"`
Password string `json:"password" out:"false"`
}func main() {
m := martini.New()
route := martini.NewRouter()// create a format -> encoder map
negotiators := make(map[string]encoder.Encoder)
negotiators["application/xml"] = encoder.XmlEncoder{}
negotiators["application/json"] = encoder.JsonEncoder{}// use the middleware
m.Use(negotiate.NegotiateFormat(negotiators))// and the right encoder will be automatically injected
route.Get("/test", func(enc encoder.Encoder) (int, []byte) {
result := &Some{"awesome", "hidden"}
return http.StatusOK, encoder.Must(enc.Encode(result))
})m.Action(route.Handle)
log.Println("Waiting for connections...")
if err := http.ListenAndServe(":8000", m); err != nil {
log.Fatal(err)
}
}
```## ToDo
* provide tools to negotiate other things (language for instance)
* write tests## License
This library is released under the MIT License. See the bundled LICENSE file for
details.