Coder Social home page Coder Social logo

iarsham / multiplexer Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 18 KB

Multiplexer provides a flexible and easy-to-use solution for grouping API routes, applying multiple middleware, and restricting HTTP methods.

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
api group http-server multiplexer mux

multiplexer's Introduction

multiplexer - A Versatile HTTP Request Router🚀

The multiplexer library provides a robust and customizable HTTP request router built on top of the standard net/http package in Go. It empowers developers to efficiently manage incoming requests, directing them to appropriate handlers based on URL patterns and methods.

Installation🛠

Prerequisites: Go 1.22 or above

  go get -u github.com/iarsham/multiplexer

Usage/Examples💡

func main() {
	mux := multiplexer.New(http.NewServeMux(), "/api")
	mux.NotFound = http.HandlerFunc(notfound)
	mux.MethodNotAllowed = http.HandlerFunc(allowed)
	dynamic := multiplexer.NewChain(logMiddleware)
	mux.Handle("GET /root", dynamic.WrapFunc(root))
	authGroup := mux.Group("/user")
	protected := dynamic.Append(authMiddleware)
	authGroup.Handle("GET /home", protected.WrapFunc(home))
	log.Fatal(http.ListenAndServe(":8000", mux))
}

Features🪜

  • Clear and Consistent Routing: Define routes using URL patterns that may include named capture groups (e.g., /users/:id).
  • Base Path Support: Configure a base path to be prepended to all route patterns, simplifying organization within nested routing scenarios.
  • Flexible Handler Registration: Register handlers using HandleFunc, Handle, or custom handler functions.
  • Customizable Not Found and Method Not Allowed Handlers: Provide tailored responses for unmatched requests or unsupported methods.
  • Sub-Routing with Grouping: Create nested routing hierarchies using the Group function, promoting better code organization.

Contributing 🤝

Contributions are always welcome!

  • Create a fork of the repository.

  • Make your changes in a separate branch.

  • Ensure your code adheres to Go's formatting and style conventions.

  • Add unit tests for your changes.

  • Submit a well-structured pull request with a clear description of your changes. ❤️‍🔥

Contributors 👨🏻‍💻👩🏼‍💻

License ⚠️

MIT

multiplexer's People

Contributors

iarsham avatar

Stargazers

Austin Songer,MIS,CEH,ESCA,Project+ (Navy Veteran) avatar purya ghahremani avatar

Watchers

 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.