package middleware import ( "fmt" "io/ioutil" "net/http" web "git.to-net.rs/marko.tikvic/webutility" ) func Headers(h http.HandlerFunc) http.HandlerFunc { return SetAccessControlHeaders(IgnoreOptionsRequests(ParseForm(h))) } func AuthUser(roles string, h http.HandlerFunc) http.HandlerFunc { return SetAccessControlHeaders(IgnoreOptionsRequests(ParseForm(Auth(roles, h)))) } func AuthUserAndLog(roles string, h http.HandlerFunc) http.HandlerFunc { return SetAccessControlHeaders(IgnoreOptionsRequests(ParseForm(LogHTTP(Auth(roles, h))))) } func LogTraffic(h http.HandlerFunc) http.HandlerFunc { return SetAccessControlHeaders(IgnoreOptionsRequests(ParseForm(LogHTTP(h)))) } func TrafficLogsHandler(w http.ResponseWriter, req *http.Request) { switch req.Method { case "GET": files, err := ioutil.ReadDir(httpLogger.GetOutDir() + "/") if err != nil { web.InternalServerError(w, req, err.Error()) return } web.SetContentType(w, "text/html; charset=utf-8") web.SetResponseStatus(w, http.StatusOK) web.WriteResponse(w, []byte("
")) inputForm := `Name | Size |
---|---|
%s | %dB |
")) web.WriteResponse(w, content) web.WriteResponse(w, []byte("")) return } }