2021-11-03 17:17:58 +00:00
|
|
|
package ksrv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-03 19:08:05 +00:00
|
|
|
"kumoly.io/lib/klog"
|
2021-11-03 17:17:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type kserver struct {
|
|
|
|
http.Server
|
2021-11-03 19:08:05 +00:00
|
|
|
l *klog.Logger
|
2021-11-03 18:09:00 +00:00
|
|
|
nolog func(r *http.Request) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listen to addr
|
|
|
|
func (s *kserver) Handle(h http.Handler) *kserver {
|
|
|
|
s.Handler = h
|
|
|
|
return s
|
2021-11-03 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Listen to addr
|
|
|
|
func (s *kserver) Listen(addr string) *kserver {
|
|
|
|
s.Addr = addr
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serve alias to ListenAndServe
|
|
|
|
func (s *kserver) Serve() error {
|
|
|
|
return s.ListenAndServe()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *kserver) ListenAndServe() error {
|
|
|
|
s.Handler = s.Middleware(s.Handler)
|
|
|
|
return s.Server.ListenAndServe()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *kserver) ListenAndServeTLS(certFile string, keyFile string) error {
|
|
|
|
s.Handler = s.Middleware(s.Handler)
|
|
|
|
return s.Server.ListenAndServeTLS(certFile, keyFile)
|
|
|
|
}
|