ksrv/test/main.go

28 lines
773 B
Go
Raw Normal View History

2021-11-03 17:17:58 +00:00
package main
import (
"errors"
"fmt"
"net/http"
2021-11-03 19:08:05 +00:00
"kumoly.io/lib/klog"
2021-11-03 17:17:58 +00:00
"kumoly.io/lib/ksrv"
)
func main() {
2021-11-03 19:08:05 +00:00
klog.PROD = false
2021-11-03 17:17:58 +00:00
mux := http.NewServeMux()
2021-11-05 13:19:45 +00:00
mux.HandleFunc("/ok", func(rw http.ResponseWriter, r *http.Request) { rw.Write([]byte("ok")) })
2021-11-03 17:17:58 +00:00
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("/out", func(rw http.ResponseWriter, r *http.Request) { arr := []int{0, 1}; fmt.Print(arr[9]) })
2021-11-03 19:08:05 +00:00
klog.Info("start")
2021-11-03 17:17:58 +00:00
2021-11-05 13:19:45 +00:00
err := ksrv.New().SetNoLogCondition(func(r *http.Request) bool {
2021-11-05 15:31:55 +00:00
return r.URL.String() == "/"
}).Handle(mux).Listen("0.0.0.0:8080").Serve()
2021-11-03 17:17:58 +00:00
if err != nil {
panic(err)
}
}