Giter VIP home page Giter VIP logo

middleware's Introduction

This repository provides a way to share any minor handlers for ion web framework. You can view the built'n supported handlers by pressing here.

Build status

Installation

$ go get github.com/get-ion/middleware/...

Middleware is just a chain handlers which can be executed before or after the main handler, can transfer data between handlers and communicate with third-party libraries, they are just functions.

Middleware Description Example
jwt Middleware checks for a JWT on the Authorization header on incoming requests and decodes it. jwt/_example
cors HTTP Access Control. cors/_example
secure Middleware that implements a few quick security wins. secure/_example
tollbooth Generic middleware to rate-limit HTTP requests. tollbooth/_examples/limit-handler
cloudwatch AWS cloudwatch metrics middleware. cloudwatch/_example
new relic Official New Relic Go Agent. newrelic/_example
prometheus Easily create metrics endpoint for the prometheus instrumentation tool prometheus/_example

How can I register middleware?

To a single route

app := ion.New()
app.Get("/mypath", myMiddleware1, myMiddleware2, func(ctx context.Context){}, func(ctx context.Context){}, myMiddleware5,myMainHandlerLast)

To a party of routes or subdomain

myparty := app.Party("/myparty", myMiddleware1,func(ctx context.Context){},myMiddleware3)
{
	//....
}

To all routes

app.Use(func(ctx context.Context){}, myMiddleware2)

To global, all routes on all subdomains on all parties

app.UseGlobal(func(ctx context.Context){}, myMiddleware2)

Can I use standard net/http handler with ion?

Yes you can, just pass the Handler inside the ion.FromStd in order to be converted into context.Handler and register it as you saw before.

Convert handler which has the form of http.Handler/HandlerFunc

package main

import (
	"github.com/get-ion/ion"
	"github.com/get-ion/ion/context"
)

func main() {
	app := ion.New()

	sillyHTTPHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
	     println(r.RequestURI)
	})

	sillyConvertedToIon := ion.FromStd(sillyHTTPHandler)
	// FromStd can take (http.ResponseWriter, *http.Request, next http.Handler) too!
	app.Use(sillyConvertedToIon)

	app.Run(ion.Addr(":8080"))
}

Contributing

If you are interested in contributing to this project, please push a PR.

People

List of all contributors

middleware's People

Contributors

hiveminded avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.