From 11dd7a3587bc67c94d978880ca99636b5048c211 Mon Sep 17 00:00:00 2001 From: uan Date: Fri, 8 Aug 2025 13:45:20 +0200 Subject: [PATCH] comments in config files with # --- miniws/webserver.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/miniws/webserver.go b/miniws/webserver.go index 09da551..3f3de2d 100644 --- a/miniws/webserver.go +++ b/miniws/webserver.go @@ -88,8 +88,19 @@ func (ws *WebServer) parseFilterPanics(fileName string) (FilterMode, []string) { panic("Error reading " + fileName + ": " + err.Error()) } - filterLines := strings.Split(string(filterContent), "\n") - readFilterMode := filterLines[0] + lines := strings.Split(string(filterContent), "\n") + var linesNoComments []string = make([]string, 0) + + for _, line := range lines { + line = strings.TrimSpace(strings.Split(line, "#")[0]) // only take portion before comments + if line == "" { + continue + } + linesNoComments = append(linesNoComments, line) + } + + readFilterMode := linesNoComments[0] + filter = linesNoComments[1:] switch readFilterMode { case "allow": @@ -100,8 +111,6 @@ func (ws *WebServer) parseFilterPanics(fileName string) (FilterMode, []string) { panic("invalid filter mode for " + fileName + ": use allow|deny") } - filter = filterLines[1:] - return filterMode, filter }