Skip to content
/ midway Public

The Go package for arranging your HTTP middleware.

License

Notifications You must be signed in to change notification settings

novrin/midway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages