You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jimzhan b6e775d28e init imports (fully compatible stdlib branch) 9 jaren geleden
internal init imports (fully compatible stdlib branch) 9 jaren geleden
modules init imports (fully compatible stdlib branch) 9 jaren geleden
LICENSE init imports (fully compatible stdlib branch) 9 jaren geleden
Makefile init imports (fully compatible stdlib branch) 9 jaren geleden
README.md init imports (fully compatible stdlib branch) 9 jaren geleden
default.go init imports (fully compatible stdlib branch) 9 jaren geleden
logger.go init imports (fully compatible stdlib branch) 9 jaren geleden
main.go init imports (fully compatible stdlib branch) 9 jaren geleden
router.go init imports (fully compatible stdlib branch) 9 jaren geleden

README.md

rex

Rex is a powerful framework for modular web development in Golang.

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.
  • Django-syntax like templating-language backed by flosch/pongo.
  • Non-intrusive/Modular design, extremely easy to use.
  • Standard & modular system based on http.Handler interface.
  • Command line tools
    • Auto-compile for .go & .html
    • Browser-based Live reload supports
  • Fully compatible with the http.Handler/http.HandlerFunc interface.

After installing Go and setting up your GOPATH, create your first server, we named it server.go here.

package main

import (
    "io"
    "net/http"

    "github.com/goanywhere/rex"
)

func main() {
    rex.Get("/", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello World")
    })
    rex.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 (
    "github.com/goanywhere/rex"
    "github.com/goanywhere/x/env"
)

func index (ctx *rex.Context) {
    ctx.Render("index.html")
}

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

    rex.Get("/", index)
    rex.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.

Modules

Modules work between http requests and the router, they are no different than the standard http.Handler. Existing modules (aka. middleware) from other frameworks like logging, authorization, session, gzipping are very easy to integrate into Rex. As long as it complies the rex.Module interface (shorcut to standard func(http.Handler) http.Handler), you can simply add one like this:

app.Use(modules.XSRF)

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

app.Use(func(next http.Handler) http.Handler {
    return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
        log.Printf("Custom Middleware Module Started")
        next.ServeHTTP(writer, request)
        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(writer, request)
    })
})

Frameworks comes & dies, 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

  • [X] Env-Based Configurations
  • [X] Test Suite
  • [X] New Project Template
  • [X] CLI Apps Integrations
  • [X] Improved Template Rendering
  • [X] Performance Boost
  • [X] Hot-Compile Runner
  • [X] Live Reload Integration
  • [X] Template Functions
  • [X] Common Modules
  • Project Wiki
  • Continuous Integration
  • Stable API