func (factory *IsHandledDemuxFactory) noHandlerFound(writer http.ResponseWriter, request *http.Request) {
	if factory.NoHandlerFound != nil {
		factory.NoHandlerFound.ServeHTTP(writer, request)
		return
	}
	writer.WriteHeader(http.StatusNotFound)
	_, _ = writer.Write([]byte{})
}
noHandlerFound provides an empty 404 for unmatched paths if NoHandlerFound is nil, otherwise call and defer to NoHandlerFound.
package xweb
import (
	"context"
	"fmt"
	"net/http"
	"strings"
)
type DemuxFactory interface {
	Build(handlers []WebHandler) (http.Handler, error)
}
type PathPrefixDemuxFactory struct {
	NoHandlerFound http.Handler
}
func (factory *PathPrefixDemuxFactory) Build(handlers []WebHandler) (http.Handler, error) {
	handlerMap := map[string]WebHandler{}
	for _, handler := range handlers {
		if existing, ok := handlerMap[handler.RootPath()]; ok {
			return nil, fmt.Errorf("duplicate root path [%s] detected for both bindings [%s] and [%s]", handler.RootPath(), handler.Binding(), existing.Binding())
		}
		handlerMap[handler.RootPath()] = handler
	}
	return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		for _, handler := range handlers {
			if strings.HasPrefix(request.URL.Path, handler.RootPath()) {
				ctx := context.WithValue(request.Context(), WebHandlerContextKey, handler)
				newRequest := request.WithContext(ctx)
				handler.ServeHTTP(writer, newRequest)
				return
			}
		}
		factory.noHandlerFound(writer, request)
	}), nil
}
func (factory *PathPrefixDemuxFactory) noHandlerFound(writer http.ResponseWriter, request *http.Request) {
	if factory.NoHandlerFound != nil {
		factory.NoHandlerFound.ServeHTTP(writer, request)
		return
	}
	writer.WriteHeader(http.StatusNotFound)
	_, _ = writer.Write([]byte{})
}
type IsHandledDemuxFactory struct {
	NoHandlerFound http.Handler
}
func (factory *IsHandledDemuxFactory) Build(handlers []WebHandler) (http.Handler, error) {
	return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		for _, handler := range handlers {
			if handler.IsHandler(request) {
				ctx := context.WithValue(request.Context(), WebHandlerContextKey, handler)
				newRequest := request.WithContext(ctx)
				handler.ServeHTTP(writer, newRequest)
				return
			}
		}
		factory.noHandlerFound(writer, request)
	}), nil
}