Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 9 roky
před 9 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 7 roky
před 8 roky
před 9 roky
před 9 roky
před 9 roky
před 7 roky
před 9 roky
před 9 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <a href="#"><img alt="rex" src="https://raw.githubusercontent.com/goanywhere/rex/assets/images/rex.png" width="160px" height="64px"></a>
  2. ===
  3. [![Build Status](https://travis-ci.org/goanywhere/rex.svg?branch=master)](https://travis-ci.org/goanywhere/rex) [![GoDoc](https://godoc.org/github.com/goanywhere/rex?status.svg)](http://godoc.org/github.com/goanywhere/rex)
  4. Rex is a library for performant & modular web development in [Go](http://golang.org/), designed to work directly with `net/http`.
  5. ## Supported Versions
  6. - [X] v1.4
  7. - [X] v1.5
  8. - [X] v1.6
  9. - [X] v1.7
  10. - [X] v1.8
  11. - [X] v1.9
  12. ## Intro
  13. Nah, not another **Web Framework**, we have that enough.The more we spend on [Go](http://golang.org/), the more clearly we realize that most lightweight, pure-stdlib conventions really do scale to large groups of developers and diverse project ecosystems. You absolutely don’t need a *Web Framework* like you normally do in other languages, simply because your code base has grown beyond a certain size. Or you believe it might grow beyond a certain size! You truly ain’t gonna need it. What we really need is just a suitable routing system, along with some common toolkits for web development, the standard idioms and practices will continue to function beautifully at scale.
  14. ## Getting Started
  15. Install the package, along with executable binary helper (**go 1.4** and greater is required):
  16. ```shell
  17. $ go get -v github.com/goanywhere/rex/...
  18. ```
  19. ## Features
  20. * Flexible Env-based configurations.
  21. * Awesome routing system provided by [Gorilla/Mux](//github.com/gorilla/mux).
  22. * Group routing system with middleware modules supports
  23. * Non-intrusive/Modular design, extremely easy to use.
  24. * Standard & modular system based on [http.Handler](http://godoc.org/net/http#Handler) interface.
  25. * Command line tools
  26. * Auto-compile/reload for .go & .html sources
  27. * Browser-based Live reload supports for HTML templates
  28. * **Fully compatible with the [http.Handler](http://godoc.org/net/http#Handler)/[http.HandlerFunc](http://godoc.org/net/http#HandlerFunc) interface.**
  29. After installing Go and setting up your [GOPATH](http://golang.org/doc/code.html#GOPATH), create your first server.
  30. ``` go
  31. package main
  32. import (
  33. "io"
  34. "net/http"
  35. "github.com/goanywhere/rex"
  36. )
  37. func main() {
  38. app := rex.New()
  39. app.Get("/", func(w http.ResponseWriter, r *http.Request) {
  40. io.WriteString(w, "Hello World")
  41. })
  42. app.Run()
  43. }
  44. ```
  45. Then start your server:
  46. ``` shell
  47. rex run
  48. ```
  49. You will now have a HTTP server running on `localhost:5000`.
  50. ## Settings
  51. All settings on Rex can be accessed via `env`, which essentially stored in `os.Environ`. By using this approach you can compile your own settings files into the binary package for deployment without exposing the sensitive settings, it also makes configuration extremly easy & flexible via both command line & application.
  52. ``` go
  53. package main
  54. import (
  55. "io"
  56. "github.com/goanywhere/env"
  57. "github.com/goanywhere/rex"
  58. )
  59. func index(w http.ResponseWriter, r *http.Request) {
  60. io.WriteString("Hey you")
  61. }
  62. func main() {
  63. // Override default 5000 port here.
  64. env.Set("PORT", 9394)
  65. app := rex.New()
  66. app.Get("/", index)
  67. app.Run()
  68. }
  69. ```
  70. You will now have the HTTP server running on `0.0.0.0:9394`.
  71. Hey, dude, why not just use those popular approaches, like file-based config? We know you'll be asking & we have the answer as well, [here](http://12factor.net/config).
  72. ## Middleware
  73. Middlware modules work between http requests and the router, they are no different than the standard http.Handler. Existing middleware modules from other frameworks like logging, authorization, session, gzipping are very easy to integrate into Rex. As long as it complies the standard `func(http.Handler) http.Handler` signature, you can simply add one like this:
  74. ``` go
  75. app.Use(middleware.XSRF)
  76. ```
  77. Since a middleware module is just the standard http.Handler, writing custom middleware is also pretty straightforward:
  78. ``` go
  79. app.Use(func(next http.Handler) http.Handler {
  80. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  81. log.Printf("Custom Middleware Module Started")
  82. next.ServeHTTP(w, r)
  83. log.Printf("Custom Middleware Module Ended")
  84. })
  85. })
  86. ```
  87. Using prefixed (aka. subrouter) router is exactly same as the main one:
  88. ```go
  89. app := rex.New()
  90. app.Get("/", func(w http.ResponseWriter, r *http.Request) {
  91. io.WriteString(w, "index page")
  92. })
  93. user := app.Group("/users")
  94. user.Use(func(next http.Handler) http.Handler {
  95. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  96. log.Printf("this is a protected page")
  97. next.ServeHTTP(w, r)
  98. })
  99. })
  100. ```
  101. ## Benchmark?
  102. Rex is built upon [Gorilla/Mux](//github.com/gorilla/mux), designed to work with standard `net/http` directly, which means it can run as fast as stdlib can without compromise. Here is a simple [wrk](https://github.com/wg/wrk) HTTP benchmark on a RMBP (2.8 GHz Intel Core i5 with 16GB memory) machine.
  103. <img alt="wrk" src="https://raw.githubusercontent.com/goanywhere/rex/assets/images/wrk.png">
  104. ## Frameworks come & die, will this be supported?
  105. Positive! Rex is an internal/fundamental project at GoAnywhere. We developed it and we are going to continue using/improving it.
  106. ##Roadmap for v1.0
  107. - [X] Env-Based Configurations
  108. - [X] CLI Apps Integrations
  109. - [X] Performance Boost
  110. - [X] Hot-Compile Runner
  111. - [X] Live Reload Integration
  112. - [X] Common Middleware Modules
  113. - [X] Continuous Integration
  114. - [X] Full Test Converage
  115. - [ ] Context Supports
  116. - [ ] [http.Handler](http://godoc.org/net/http#Handler) interface based rendering
  117. - [ ] Project Wiki
  118. - [ ] Stable API