1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Added files from the first prototype.

This commit is contained in:
Sascha L. Teichmann 2021-11-16 13:58:54 +01:00
parent c2a483fc95
commit fed66c4e27
13 changed files with 1529 additions and 0 deletions

38
cmd/csaf_provider/mux.go Normal file
View file

@ -0,0 +1,38 @@
package main
import (
"net/http"
"os"
"strings"
)
type pathInfoMux struct {
routes map[string]http.Handler
}
func newPathInfoMux() *pathInfoMux {
return &pathInfoMux{routes: map[string]http.Handler{}}
}
func (pim *pathInfoMux) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
pi := os.Getenv("PATH_INFO")
if h, ok := pim.routes[pi]; ok {
h.ServeHTTP(rw, req)
return
}
for k, v := range pim.routes {
if strings.HasPrefix(k, pi) {
v.ServeHTTP(rw, req)
return
}
}
http.NotFound(rw, req)
}
func (pim *pathInfoMux) handle(pattern string, handler http.Handler) {
pim.routes[pattern] = handler
}
func (pim *pathInfoMux) handleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
pim.handle(pattern, http.HandlerFunc(handler))
}