Pleasures for Web in Golang

rex

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.

wrk

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
Similar Resources

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Jan 3, 2023

BANjO is a simple web framework written in Go (golang)

BANjO banjo it's a simple web framework for building simple web applications Install $ go get github.com/nsheremet/banjo Example Usage Simple Web App

Sep 27, 2022

The web framework for Golang

The web framework for Golang

uAdmin the Golang Web Framework Easy to use, blazing fast and secure. Originally open source by IntegrityNet Solutions and Services For Documentation:

Dec 24, 2022

Eudore is the core of a golang lightweight web framework.

Eudore eudore是一个golang轻量级web框架核心,可以轻松扩展成一个技术栈专用框架,具有完整框架设计体系。 反馈和交流请加群组:QQ群373278915。 Features 易扩展:主要设计目标、核心全部解耦,接口即为逻辑。 简单:对象语义明确,框架代码量少复杂度低,无依赖库。 易用

Nov 7, 2022

a golang web mvc framework, like asp.net mvc.

goku goku is a Web Mvc Framework for golang, mostly like ASP.NET MVC. doc & api Installation To install goku, simply run go get github.com/QLeelulu/go

Dec 7, 2022

Fast and Reliable Golang Web Framework

Fast and Reliable Golang Web Framework

Gramework The Good Framework Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware What is i

Dec 18, 2022

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance. Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance.  Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo(For English Documentation Click Here) 一个使用Go语言开发的web框架。 相关工具及插件 tiger tiger是一个专门为Tigo框架量身定做的脚手架工具,可以使用tiger新建Tigo项目或者执行其他操作。

Jan 5, 2023

An app skeleton for very simple golang web applications

Golang App Skeleton This is a skeleton for a golang web application optimized for simplicity and rapid development. Prerequisites Go 1.15 or greater O

Oct 16, 2022

A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL

backend A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL How to run Make sure you have Go installed (download).

Jan 1, 2023
Comments
  • Custom mux router

    Custom mux router

    Hi!

    There's any way to register custom mux routers to Rex app? The server.mux is not exported and can't be modified.

    I need to use subdomain at routes (using the mux.Host()) to access it's value inside views (using mux.Vars), e.g.:

    app := rex.New()
    router := mux.NewRouter().Host("{customer:[a-z]+}.test.com").Subrouter()
    router.HandleFunc("/", indexHandler)
    

    I want to do something like this: app.Mux = router

    Or maybe something more idiomatic: app.Router = router

    Best regards!

⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Dec 8, 2022
Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

Nov 14, 2022
re:Web enables classic web applications to run on AWS Lambda.
re:Web enables classic web applications to run on AWS Lambda.

re:Web re:Web enables classic web applications to run on AWS Lambda. re:Web interfaces with the Lambda Runtime API. It translates API Gateway requests

Jan 1, 2023
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch

It is still under development, so please do not use it. We plan to release v.1.0.0 in the summer. roche is a web framework optimized for microservice

Sep 19, 2022
The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

Jul 14, 2022
A powerful go web framework for highly scalable and resource efficient web application

webfr A powerful go web framework for highly scalable and resource efficient web application Installation: go get -u github.com/krishpranav/webfr Exa

Nov 28, 2021
A powerful go web framework for highly scalable and resource efficient web application

A powerful go web framework for highly scalable and resource efficient web application

Oct 3, 2022
Chainrand contract + web frontend + web backend

Chainrand-web This repo contains the implementation of Chainrand. https://chainrand.io Smart Contract Contains functionality to tie a Chainlink VRF to

Dec 8, 2021
A web app built using Go Buffalo web framework

Welcome to Buffalo Thank you for choosing Buffalo for your web development needs. Database Setup It looks like you chose to set up your application us

Feb 7, 2022