Skip to content

nanoninja/drago

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drago

Drago is an idiomatic HTTP Middleware for Go.

license godoc build status Coverage Status go report card codebeat

Installation

go get github.com/nanoninja/drago

Getting Started

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

package main

import (
	"fmt"
	"net/http"

	"github.com/nanoninja/drago"
)

func DemoMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		fmt.Println("Demo Middleware Before")
		next.ServeHTTP(rw, r)
        fmt.Println("Demo Middleware After")
	})
}

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(rw, "Welcome to the home page!")
	})

	handler := drago.New(DemoMiddleware).Handler(mux)

	http.ListenAndServe(":3000", handler)
}

Usage examples

Use

d := drago.New()

d.Use(Middleware1, Middleware2)

handler := d.Handler(http.NewServeMux())

Extend

a := drago.New(Middleware1, Middleware2)
b := drago.New(Middleware3, Middleware4)

a.Extend(b) // a == Middleware1, Middleware2, Middleware3, Middleware4

handler := a.Handler(http.NewServeMux())

HandlerFunc

d := drago.New(Middleware1, Middleware2)

handler := d.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(rw, "Welcome!")
})

Third Party Middleware

Here is a current list of Drago compatible middleware :

Middleware Author Description
Bulma Vincent Letourneau Basic authentication implementation for Go.
Goshi Vincent Letourneau Goshi is an extension of http.ResponseWriter written in Go.

License

Drago is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a BSD license.

About

Drago is an idiomatic HTTP Middleware for Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages