ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - goanywhere/rex: Pleasures for Web in Golang
Pleasures for Web in Golang. Contribute to goanywhere/rex development by creating an account on GitHub.
Visit Site

GitHub - goanywhere/rex: Pleasures for Web in Golang

GitHub - goanywhere/rex: Pleasures for Web in Golang

Build Status GoDoc

Rex is a library for performant & modular web development in Go, designed to work directly with net/http.

Supported Versions

  • v1.4
  • v1.5
  • v1.6
  • v1.7
  • v1.8
  • v1.9

Intro

Nah, not another Web Framework, we have that enough.The more we spend on Go, 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.

Getting Started

Install the package, along with executable binary helper (go 1.4 and greater is required):

$ go get -v github.com/goanywhere/rex/...

Features

  • Flexible Env-based configurations.
  • Awesome routing system provided by Gorilla/Mux.
  • Group routing system with middleware modules supports
  • Non-intrusive/Modular design, extremely easy to use.
  • Standard & modular system based on http.Handler interface.
  • Command line tools
    • Auto-compile/reload for .go & .html sources
    • Browser-based Live reload supports for HTML templates
  • Fully compatible with the http.Handler/http.HandlerFunc interface.

After installing Go and setting up your GOPATH, create your first server.

package main

import (
    "io"
    "net/http"

    "github.com/goanywhere/rex"
)

func main() {
    app := rex.New()
    app.Get("/", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello World")
    })
    app.Run()
}

Then start your server:

rex run

You will now have a HTTP server running on localhost:5000.

Settings

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.

package main

import (
    "io"

    "github.com/goanywhere/env"
    "github.com/goanywhere/rex"
)

func index(w http.ResponseWriter, r *http.Request) {
    io.WriteString("Hey you")
}

func main() {
    // Override default 5000 port here.
    env.Set("PORT", 9394)

    app := rex.New()
    app.Get("/", index)
    app.Run()
}

You will now have the HTTP server running on 0.0.0.0:9394.

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.

Middleware

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:

app.Use(middleware.XSRF)

Since a middleware module is just the standard http.Handler, writing custom middleware is also pretty straightforward:

app.Use(func(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        log.Printf("Custom Middleware Module Started")
        next.ServeHTTP(w, r)
        log.Printf("Custom Middleware Module Ended")
    })
})

Using prefixed (aka. subrouter) router is exactly same as the main one:

app := rex.New()
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "index page")
})

user := app.Group("/users")
user.Use(func(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        log.Printf("this is a protected page")
        next.ServeHTTP(w, r)
    })
})

Benchmark?

Rex is built upon 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 HTTP benchmark on a RMBP (2.8 GHz Intel Core i5 with 16GB memory) machine.

Frameworks come & die, will this be supported?

Positive! Rex is an internal/fundamental project at GoAnywhere. We developed it and we are going to continue using/improving it.

##Roadmap for v1.0

  • Env-Based Configurations
  • CLI Apps Integrations
  • Performance Boost
  • Hot-Compile Runner
  • Live Reload Integration
  • Common Middleware Modules
  • Continuous Integration
  • Full Test Converage
  • Context Supports
  • http.Handler interface based rendering
  • Project Wiki
  • Stable API

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory