{"id":13367408,"url":"https://github.com/Goanywhere/rex","last_synced_at":"2025-03-12T18:32:35.748Z","repository":{"id":21958337,"uuid":"25282984","full_name":"goanywhere/rex","owner":"goanywhere","description":"Pleasures for Web in Golang","archived":false,"fork":false,"pushed_at":"2017-12-22T03:25:41.000Z","size":5979,"stargazers_count":33,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-16T23:32:36.589Z","etag":null,"topics":["benchmark","go","golang","middleware","modular","rex","scale","stdlib"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goanywhere.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-16T02:26:18.000Z","updated_at":"2024-07-09T09:48:49.000Z","dependencies_parsed_at":"2022-08-18T01:00:18.283Z","dependency_job_id":null,"html_url":"https://github.com/goanywhere/rex","commit_stats":null,"previous_names":["goanywhere/web"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goanywhere%2Frex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goanywhere%2Frex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goanywhere%2Frex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goanywhere%2Frex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goanywhere","download_url":"https://codeload.github.com/goanywhere/rex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271635,"owners_count":20264496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","go","golang","middleware","modular","rex","scale","stdlib"],"created_at":"2024-07-30T00:01:47.369Z","updated_at":"2025-03-12T18:32:35.312Z","avatar_url":"https://github.com/goanywhere.png","language":"Go","readme":"\u003ca href=\"#\"\u003e\u003cimg alt=\"rex\" src=\"https://raw.githubusercontent.com/goanywhere/rex/assets/images/rex.png\" width=\"160px\" height=\"64px\"\u003e\u003c/a\u003e\n===\n[![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)\n\nRex is a library for performant \u0026 modular web development in [Go](http://golang.org/), designed to work directly with `net/http`.\n\n## Supported Versions\n- [X] v1.4\n- [X] v1.5\n- [X] v1.6\n- [X] v1.7\n- [X] v1.8\n- [X] v1.9\n\n\n## Intro\n\nNah, 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.\n\n## Getting Started\n\nInstall the package, along with executable binary helper (**go 1.4** and greater is required):\n\n```shell\n$ go get -v github.com/goanywhere/rex/...\n```\n\n## Features\n* Flexible Env-based configurations.\n* Awesome routing system provided by [Gorilla/Mux](//github.com/gorilla/mux).\n* Group routing system with middleware modules supports\n* Non-intrusive/Modular design, extremely easy to use.\n* Standard \u0026 modular system based on [http.Handler](http://godoc.org/net/http#Handler) interface.\n* Command line tools\n    * Auto-compile/reload for .go \u0026 .html sources\n    * Browser-based Live reload supports for HTML templates\n* **Fully compatible with the [http.Handler](http://godoc.org/net/http#Handler)/[http.HandlerFunc](http://godoc.org/net/http#HandlerFunc) interface.**\n\n\nAfter installing Go and setting up your [GOPATH](http://golang.org/doc/code.html#GOPATH), create your first server.\n\n``` go\npackage main\n\nimport (\n    \"io\"\n    \"net/http\"\n\n    \"github.com/goanywhere/rex\"\n)\n\nfunc main() {\n    app := rex.New()\n    app.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        io.WriteString(w, \"Hello World\")\n    })\n    app.Run()\n}\n```\n\nThen start your server:\n``` shell\nrex run\n```\n\nYou will now have a HTTP server running on `localhost:5000`.\n\n\n\n\n## Settings\n\nAll 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 \u0026 flexible via both command line \u0026 application.\n\n``` go\npackage main\n\nimport (\n    \"io\"\n\n    \"github.com/goanywhere/env\"\n    \"github.com/goanywhere/rex\"\n)\n\nfunc index(w http.ResponseWriter, r *http.Request) {\n    io.WriteString(\"Hey you\")\n}\n\nfunc main() {\n    // Override default 5000 port here.\n    env.Set(\"PORT\", 9394)\n\n    app := rex.New()\n    app.Get(\"/\", index)\n    app.Run()\n}\n```\n\nYou will now have the HTTP server running on `0.0.0.0:9394`.\n\nHey, dude, why not just use those popular approaches, like file-based config? We know you'll be asking \u0026 we have the answer as well, [here](http://12factor.net/config).\n\n\n## Middleware\n\nMiddlware 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:\n\n``` go\napp.Use(middleware.XSRF)\n```\n\n\nSince a middleware module is just the standard http.Handler, writing custom middleware is also pretty straightforward:\n\n``` go\napp.Use(func(next http.Handler) http.Handler {\n    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n        log.Printf(\"Custom Middleware Module Started\")\n        next.ServeHTTP(w, r)\n        log.Printf(\"Custom Middleware Module Ended\")\n    })\n})\n```\n\nUsing prefixed (aka. subrouter) router is exactly same as the main one:\n\n```go\napp := rex.New()\napp.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n    io.WriteString(w, \"index page\")\n})\n\nuser := app.Group(\"/users\")\nuser.Use(func(next http.Handler) http.Handler {\n    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n        log.Printf(\"this is a protected page\")\n        next.ServeHTTP(w, r)\n    })\n})\n```\n\n## Benchmark?\n\nRex 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.\n\n\u003cimg alt=\"wrk\" src=\"https://raw.githubusercontent.com/goanywhere/rex/assets/images/wrk.png\"\u003e\n\n\n## Frameworks come \u0026 die, will this be supported?\n\nPositive! Rex is an internal/fundamental project at GoAnywhere. We developed it and we are going to continue using/improving it.\n\n\n##Roadmap for v1.0\n\n- [X] Env-Based Configurations\n- [X] CLI Apps Integrations\n- [X] Performance Boost\n- [X] Hot-Compile Runner\n- [X] Live Reload Integration\n- [X] Common Middleware Modules\n- [X] Continuous Integration\n- [X] Full Test Converage\n- [ ] Context Supports\n- [ ] [http.Handler](http://godoc.org/net/http#Handler) interface based rendering\n- [ ] Project Wiki\n- [ ] Stable API\n","funding_links":[],"categories":["Web 框架"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoanywhere%2Frex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoanywhere%2Frex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoanywhere%2Frex/lists"}