novrin / midway

The Go package for arranging your HTTP middleware.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

midway

GoDoc tests Go Report Card

midway is a micro Go package for arranging your HTTP middleware.

Installation

go get github.com/novrin/midway

Usage

A Queue returns a Middleware where the slice of given middlewares are applied first-in-first-out. The last middleware in the slice will execute first.

package main

import (
	"net/http"

	"github.com/novrin/midway"
)

func main() {
	// Use Queue to arrange middleware to execute secureHeaders first.
	queued := midway.Queue(corsHeaders, secureHeaders)

	app := http.HandlerFunc(hello)
	http.ListenAndServe(":1313", queued(app))
	// serves secureHeaders(corsHeaders(app))
}

A Stack returns a Middleware where the slice of given middlewares are applied last-in-first-out. The first middleware in the slice will execute first.

package main

import (
	"net/http"

	"github.com/novrin/midway"
)

func main() {
	// Use Stack to arrange middleware to execute corsHeaders first.
	stacked := midway.Stack(corsHeaders, secureHeaders)

	app := http.HandlerFunc(hello)
	http.ListenAndServe(":1313", stacked(app))
	// serves corsHeaders(secureHeaders(app))
}

License

Copyright (c) 2023-present novrin

Licensed under MIT License

About

The Go package for arranging your HTTP middleware.

License:MIT License


Languages

Language:Go 100.0%