Compare commits

...

No commits in common. "6cae096a9b6ec023d9628c93f59b4c55ddfb7acb" and "894dbc1bbf5c4e7ef6eae0503029cc016f64d322" have entirely different histories.

2 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# kmux # ksrv
A extended gorilla mux with logging and panic recovery A extended http.Server with logging and panic recovery
## Examples ## Examples
@ -13,20 +13,22 @@ import (
"net/http" "net/http"
"kumoly.io/core/log" "kumoly.io/core/log"
"kumoly.io/lib/kmux" "kumoly.io/lib/ksrv"
) )
func main() { func main() {
log.PROD = false log.PROD = false
mux := kmux.NewRouter() mux := http.NewServeMux()
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { rw.Write([]byte("ok")) }) 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("/err", func(rw http.ResponseWriter, r *http.Request) { ksrv.Abort(rw, errors.New("small err")) })
mux.HandleFunc("/panic", func(rw http.ResponseWriter, r *http.Request) { panic(500) }) 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]) }) mux.HandleFunc("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) })
log.Info("start") log.Info("start")
err := mux.Server().Listen("0.0.0.0:8081").Serve()
err := ksrv.New().Listen("0.0.0.0:8080").Serve()
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
``` ```

View File

@ -18,7 +18,7 @@ func main() {
mux.HandleFunc("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) }) mux.HandleFunc("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) })
log.Info("start") log.Info("start")
err := ksrv.New().Listen("0.0.0.0:8081").Serve() err := ksrv.New().Listen("0.0.0.0:8080").Serve()
if err != nil { if err != nil {
panic(err) panic(err)
} }