ironmux

package module
v0.0.0-...-2a67a25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 1 Imported by: 0

README

IronMux

ironmux is a high performance, zero dependency, middleware focused router used for handling HTTP requests. Its built around the idea of having a request pipeline and adding middleware as you see fit. There are some middleware that comes included, the main one being Endpoints which allows for you to map HTTP verbs to handlers using the standard http.ResponseWriter and http.Request.

📦 Installation

go get -u github.com/ironfang-ltd/ironmux

👨‍💻 Basic Example

package main

import (
	"log"
	"net/http"

	"github.com/ironfang-ltd/ironmux"
	"github.com/ironfang-ltd/ironmux/middleware"
)

func main() {

	// Create a new instance of the router
	r := ironmux.NewRouter()

	// Add the endpoint middleware
	r.UseMiddleware(middleware.Endpoints(func(e middleware.EndpointsBuilder) {
		e.Get("/", func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("Hello!"))
		})
	}))

	log.Fatal(srv.ListenAndServe("127.0.0.1:8000", r.Build()))
}

There are more examples that can be found in the examples directory.

😎 Middleware

There are several included middlewares that can be used or feel free to make your own.

Middleware Description
Endpoints Adds basic HTTP routing for GET, POST etc..
Logging Logs the request to the console
Files Used to serve static files
RequestID Creates an ID for the request and adds it to a response header
Spa Used to serve index.html from a directory, typically used as the last in the pipeline
Time Prints the request execution time to the console
ProxyHeaders Parsed proxy headers such as X-Forwarded-For or X-Real-IP

✌ Disclaimer

This is my first attempt at learning go as a .NET developer, this is also my first open source project. If you have any advice, contributions or constructive critisism please feel free to help! 😊

📜 License

(c) Copyright 2021, Ironfang Ltd.

Licensed under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a function that runs in the order they are added before any routing

type Router

type Router interface {
	UseMiddleware(middleware Middleware)

	Build() RouterHandler
}

Router represents an instance of the router.

func NewRouter

func NewRouter() Router

NewRouter creates an instance of the router.

type RouterHandler

type RouterHandler interface {
	ServeHTTP(w http.ResponseWriter, req *http.Request)
}

RouterHandler represents a built handler for the router

Directories

Path Synopsis
_examples
spa

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL