MCPcopy Index your code
hub / github.com/DBarbosaDev/supermuxer

github.com/DBarbosaDev/supermuxer @v0.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.2 ↗ · + Follow
23 symbols 32 edges 1 files 2 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

SuperMuxer

Super useful Go package to configure your HTTP routes using only the standard library. Define routes, middlewares, groups, and subgroups effortlessly!

This package acts like a Swiss Army Knife: It is tiny and compact, providing everything you need in just one file with less than 200 lines of code.

SuperMuxer is for you if:

  • You want to declaratively define your HTTP routes while using only the standard library.
  • You want to define middlewares for your routes, groups, and subgroups while still relying on the standard library.
  • You don’t want to use third-party libraries bloated with excessive functionalities that you might never use.

How to Use

Simply clone the file into your project or import it using the following command:

go get github.com/dbarbosadev/supermuxer@v0.1.1

Functionalities

Declarative route creation


serverMux := http.NewServeMux()
superRouter := supermuxer.New(serverMux)

superRouter.Get("/users", handler).Put("/users/{id}", handler)
superRouter.Post("/login", handler)

Middleware association


serverMux := http.NewServeMux()
superRouter := supermuxer.New(serverMux)

superRouter.AddMiddlewares(middleware1, middleware2)
superRouter.Get("/users", handler).Put("/users/{id}", handler)
superRouter.Post("/login", handler)

Groups

Create a group of routes from a copy of the original router without middlewares. This allows you to define separate route structures while maintaining the original route path.


serverMux := http.NewServeMux()
superRouter := supermuxer.New(serverMux)
superRouter.AddMiddlewares(middleware1, middleware2)

// Route "POST /login" with middleware1 and middleware2
superRouter.Post("/login", handler)

// Creates the users group
userRouter := superRouter.Group("/users")
// Group Route "GET /users" without middlewares
userRouter.Get("", handler)

userRouter.AddMiddlewares(middleware3)
// Group Route "Put /users/{id}" with middleware3
userRouter.Put("/{id}", handler)


Subgroups

Works the same way as the Group function, but the subgroup reuses the middlewares from the original router. This makes it easy to maintain middleware consistency across related routes.


serverMux := http.NewServeMux()
superRouter := supermuxer.New(serverMux)
superRouter.AddMiddlewares(middleware1, middleware2)

// Route "POST /login" with middleware1 and middleware2
superRouter.Post("/login", handler)

// Creates the users group
userRouter := superRouter.SubGroup("/users")
// Group Route "GET /users" with middlewares1 and middlewares2
userRouter.Get("", handler)

userRouter.AddMiddlewares(middleware3)
// Group Route "Put /users/{id}" with middlewares1, middlewares2 and middlewares3
userRouter.Put("/{id}", handler)

Extension points exported contracts — how you extend this code

Router (Interface)
(no doc) [1 implementers]
supermuxer.go
MiddlewareFunc (FuncType)
(no doc)
supermuxer.go

Core symbols most depended-on inside this repo

setRoute
called by 5
supermuxer.go
getFullPath
called by 1
supermuxer.go
handlerWithMiddlewares
called by 1
supermuxer.go
Get
called by 0
supermuxer.go
Post
called by 0
supermuxer.go
Put
called by 0
supermuxer.go
Delete
called by 0
supermuxer.go
Patch
called by 0
supermuxer.go

Shape

Method 16
Function 4
FuncType 1
Interface 1
Struct 1

Languages

Go100%

Modules by API surface

supermuxer.go23 symbols

For agents

$ claude mcp add supermuxer \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact