Skip to content
easy-middleware is a lightweight json middleware stack for Go >= 1.7.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
body_limit.go
body_limit_test.go
chain.go
chain_test.go
cors.go
cors_test.go
delay.go
delay_test.go
dump_incoming_request.go
dump_incoming_request_test.go
helper.go
is_valid.go
is_valid_test.go
json.go
json_header_check.go
json_header_check_test.go
logging.go
logging_test.go
nocache.go
nocache_test.go
recovery.go
recovery_test.go
sql_db.go
sql_db_test.go
timeout.go
timeout_test.go
urlquery.go
urlquery_test.go
with_value.go
with_value_test.go

README.md

Build Status

easy-middleware

What is easy-middleware ?

easy-middleware is a lightweight json middleware stack for Go >= 1.7.

Features:

  • Dump incoming request middleware
  • Set body limit middleware
  • Json header check middleware
  • Validator middleware
  • Sql db middleware
  • Recovery middleware
  • With value middleware
  • Json response writer middleware

Feature request are welcome

Example :

    package main

    import (
        "net/http"
        "github.com/donutloop/easy-middleware"
    )

    func main() {

        stack := easy_middleware.New()
    	stack.Add(easy_middleware.Json())
    	stack.Add(easy_middleware.SqlDb("postgres", "postgres://postgres:postgres@db/postgres?sslmode=disable"))
    
        http.Handle("/user", stack.Then(http.HandlerFunc(userHandler)))
        http.ListenAndServe(":80", nil)
    }

    func userHandler(rw http.ResponseWriter, req *http.Request) {
         jrw := rw.(*easy_middleware.JsonResponseWriter)          
          
         var db *sql.DB
         if rv := r.Context().Value("db"); rv != nil {
         		if v, ok := rv.(*sql.DB); ok {
         			 db = v 
         		} else if err := rv.(*easy_middleware.DatabaseError); err != nil {
         			 jrw.WriteError(err, http.StatusInternalServerError)
         			 return 
         		}
         }  
        //...
        
    }

More documentation comming soon

You can’t perform that action at this time.