default 404 handler 등록
This commit is contained in:
12
server.go
12
server.go
@ -146,6 +146,17 @@ func isTlsEnabled(fileout ...*string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registUnhandledPattern(serveMux ServerMuxInterface) {
|
||||||
|
defer func() {
|
||||||
|
recover()
|
||||||
|
}()
|
||||||
|
|
||||||
|
serveMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
logger.Println("page not found :", r.URL.Path)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// NewHTTPServer :
|
// NewHTTPServer :
|
||||||
func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server {
|
func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server {
|
||||||
if isTlsEnabled() && port == 80 {
|
if isTlsEnabled() && port == 80 {
|
||||||
@ -155,6 +166,7 @@ func NewHTTPServerWithPort(serveMux ServerMuxInterface, port int) *Server {
|
|||||||
serveMux.HandleFunc(MakeHttpHandlerPattern("welcome"), welcomeHandler)
|
serveMux.HandleFunc(MakeHttpHandlerPattern("welcome"), welcomeHandler)
|
||||||
serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_chceck"), healthCheckHandler)
|
serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_chceck"), healthCheckHandler)
|
||||||
serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_check"), healthCheckHandler)
|
serveMux.HandleFunc(MakeHttpHandlerPattern("lb_health_check"), healthCheckHandler)
|
||||||
|
registUnhandledPattern(serveMux)
|
||||||
|
|
||||||
server := &Server{
|
server := &Server{
|
||||||
httpserver: &http.Server{Addr: addr, Handler: serveMux},
|
httpserver: &http.Server{Addr: addr, Handler: serveMux},
|
||||||
|
|||||||
Reference in New Issue
Block a user