| 1 | Goji |
| 2 | ==== |
| 3 | |
| 4 | [](https://godoc.org/goji.io) [](https://travis-ci.org/goji/goji) |
| 5 | |
| 6 | Goji is a HTTP request multiplexer, similar to [`net/http.ServeMux`][servemux]. |
| 7 | It compares incoming requests to a list of registered [Patterns][pattern], and |
| 8 | dispatches to the [http.Handler][handler] that corresponds to the first matching |
| 9 | Pattern. Goji also supports [Middleware][middleware] (composable shared |
| 10 | functionality applied to every request) and uses the standard |
| 11 | [`context`][context] package to store request-scoped values. |
| 12 | |
| 13 | [servemux]: https://golang.org/pkg/net/http/#ServeMux |
| 14 | [pattern]: https://godoc.org/goji.io#Pattern |
| 15 | [handler]: https://golang.org/pkg/net/http/#Handler |
| 16 | [middleware]: https://godoc.org/goji.io#Mux.Use |
| 17 | [context]: https://golang.org/pkg/context |
| 18 | |
| 19 | |
| 20 | Quick Start |
| 21 | ----------- |
| 22 | |
| 23 | ```go |
| 24 | package main |
| 25 | |
| 26 | import ( |
| 27 | "fmt" |
| 28 | "net/http" |
| 29 | |
| 30 | "goji.io" |
| 31 | "goji.io/pat" |
| 32 | ) |
| 33 | |
| 34 | func hello(w http.ResponseWriter, r *http.Request) { |
| 35 | name := pat.Param(r, "name") |
| 36 | fmt.Fprintf(w, "Hello, %s!", name) |
| 37 | } |
| 38 | |
| 39 | func main() { |
| 40 | mux := goji.NewMux() |
| 41 | mux.HandleFunc(pat.Get("/hello/:name"), hello) |
| 42 | |
| 43 | http.ListenAndServe("localhost:8000", mux) |
| 44 | } |
| 45 | ``` |
| 46 | |
| 47 | Please refer to [Goji's GoDoc Documentation][godoc] for a full API reference. |
| 48 | |
| 49 | [godoc]: https://godoc.org/goji.io |
| 50 | |
| 51 | |
| 52 | Stability |
| 53 | --------- |
| 54 | |
| 55 | Goji's API was recently updated to use the new `net/http` and `context` |
| 56 | integration, and is therefore some of its interfaces are in a state of flux. We |
| 57 | don't expect any further changes to the API, and expect to be able to announce |
| 58 | API stability soon. Goji is suitable for use in production. |
| 59 | |
| 60 | Prior to Go 1.7, Goji promised API stability with a different API to the one |
| 61 | that is offered today. The author broke this promise, and does not take this |
| 62 | breach of trust lightly. While stability is obviously extremely important, the |
| 63 | author and community have decided to follow the broader Go community in |
| 64 | standardizing on the standard library copy of the `context` package. |
| 65 | |
| 66 | Users of the old API can find that familiar API on the `net-context` branch. The |
| 67 | author promises to maintain both the `net-context` branch and `master` for the |
| 68 | forseeable future. |
| 69 | |
| 70 | |
| 71 | Community / Contributing |
| 72 | ------------------------ |
| 73 | |
| 74 | Goji maintains a mailing list, [gojiberries][berries], where you should feel |
| 75 | welcome to ask questions about the project (no matter how simple!), to announce |
| 76 | projects or libraries built on top of Goji, or to talk about Goji more |
| 77 | generally. Goji's author (Carl Jackson) also loves to hear from users directly |
| 78 | at his personal email address, which is available on his GitHub profile page. |
| 79 | |
| 80 | Contributions to Goji are welcome, however please be advised that due to Goji's |
| 81 | stability guarantees interface changes are unlikely to be accepted. |
| 82 | |
| 83 | All interactions in the Goji community will be held to the high standard of the |
| 84 | broader Go community's [Code of Conduct][conduct]. |
| 85 | |
| 86 | [berries]: https://groups.google.com/forum/#!forum/gojiberries |
| 87 | [conduct]: https://golang.org/conduct |