From 020cc8ad6760a4b9ad8f2e5863554cfa781a3998 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 23 Feb 2025 21:54:52 +0100 Subject: [PATCH] refactor(server): Improve Wireguard indexes Signed-off-by: Myzel394 --- server/handlers/wireguard/indexes/indexes.go | 7 ++++++ .../wireguard/indexes/indexes_handlers.go | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 server/handlers/wireguard/indexes/indexes_handlers.go diff --git a/server/handlers/wireguard/indexes/indexes.go b/server/handlers/wireguard/indexes/indexes.go index fce2081..3c58f77 100644 --- a/server/handlers/wireguard/indexes/indexes.go +++ b/server/handlers/wireguard/indexes/indexes.go @@ -1 +1,8 @@ package indexes + +import "config-lsp/handlers/wireguard/ast" + +type WGIndexes struct { + // map of: section name -> WGSection + SectionsByName map[string][]*ast.WGSection +} diff --git a/server/handlers/wireguard/indexes/indexes_handlers.go b/server/handlers/wireguard/indexes/indexes_handlers.go new file mode 100644 index 0000000..c332e70 --- /dev/null +++ b/server/handlers/wireguard/indexes/indexes_handlers.go @@ -0,0 +1,22 @@ +package indexes + +import ( + "config-lsp/common" + "config-lsp/handlers/wireguard/ast" +) + +func CreateIndexes(config *ast.WGConfig) (*WGIndexes, []common.LSPError) { + errs := make([]common.LSPError, 0) + indexes := &WGIndexes{ + SectionsByName: make(map[string][]*ast.WGSection), + } + + for _, section := range config.Sections { + indexes.SectionsByName[section.Header.Name] = append( + indexes.SectionsByName[section.Header.Name], + section, + ) + } + + return indexes, errs +}