Go to file
Evan Chen 08739831d3 update 2021-11-04 01:17:58 +08:00
test update 2021-11-04 01:17:58 +08:00
README.md update 2021-11-04 01:17:58 +08:00
go.mod update 2021-11-04 01:17:58 +08:00
go.sum update 2021-11-04 01:17:58 +08:00
kmux.go update 2021-11-04 01:17:58 +08:00
net.go update 2021-11-04 01:17:58 +08:00
server.go update 2021-11-04 01:17:58 +08:00
util.go update 2021-11-04 01:17:58 +08:00

README.md

kmux

A extended gorilla mux with logging and panic recovery

Examples

package main

import (
	"errors"
	"fmt"
	"net/http"

	"kumoly.io/core/log"
	"kumoly.io/lib/kmux"
)

func main() {
	log.PROD = false
	mux := kmux.NewRouter()
	mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { rw.Write([]byte("ok")) })
	mux.HandleFunc("/err", func(rw http.ResponseWriter, r *http.Request) { kmux.Abort(rw, errors.New("small err")) })
	mux.HandleFunc("/panic", func(rw http.ResponseWriter, r *http.Request) { panic(500) })
	mux.HandleFunc("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) })
	log.Info("start")
	err := mux.Server().Listen("0.0.0.0:8081").Serve()
	if err != nil {
		panic(err)
	}
}