Categorygithub.com/hyperjumptech/hyper-mux
modulepackage
1.1.0
Repository: https://github.com/hyperjumptech/hyper-mux.git
Documentation: pkg.go.dev

# README

hyper-mux

A very simplified Mux focused for ease of use.

go get github.com/hyperjumptech/hyper-mux

How to use the Mux

The following is how you going to use Hyper-Mux with vanilla http.Server

import (
    mux "github.com/hyperjumptech/hyper-mux"
    "net/http"
)

var (
    hmux := mux.NewHyperMux()	
)

...
theServer := &http.Server{
    Addr:     "0.0.0.0:8080",
    Handler:  hmux,
}
err := theServer.ListenAndServe()
if err != nil {
    panic(err.Error())
}
...

Adding Routes

First we create the route's handler function

func HandleHelloHyperMux(w http.ResponseWriter, r *http.Request) {
    hmux.WriteString(w, http.StatusOK, "Hello Hyper-Mux")
}

Then we map the HandleFunc function to the route

hmux.AddRoute("/", hmux.MethodGet, HandleHelloHyperMux)

Using Middleware

First we create the middleware

func ContextSetter(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        next.ServeHTTP(w,r)
        fmt.Println("POST CALL")
    })
}

Then we add it to our middleware chain

hmux.UseMiddleware(ContextSetter)

# Functions

ContextSetterMiddleware is a middleware function that will ensure the request context existance.
GetRequestID will retrieve the RequestID value from context if ContextSetterMiddleware middleware is used.
GZIPCompressMiddleware is a wrapper for easy GZIP Content Handling.
InternalServerError writes error message to the http.ResponseWriter.
No description provided by the author
NewCORSMiddleware will create CORS middleware to be used in your web app this middleware will handle the OPTIONS method automatically.
NewHyperMux creates new instance of HyperMux.
WriteJson simply writes a JSON to the http.ResponseWriter of type application/json if the marshaled data is not marshallable to json, it write an internal server error.
WriteString simply write to the http.ResponseWriter a text of type text/plain.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

HyperMux holds all the end-point routings and middlewares.

# Type aliases

No description provided by the author