From d456f4a569e2acfa9e337cc447c4f323d27ecb4c Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:47:42 +0200 Subject: [PATCH] fix(wireguard): Improvements --- handlers/wireguard/parser.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/handlers/wireguard/parser.go b/handlers/wireguard/parser.go index 33dc835..82d3c02 100644 --- a/handlers/wireguard/parser.go +++ b/handlers/wireguard/parser.go @@ -134,7 +134,7 @@ func (p *wireguardParser) parseFromString(input string) []lineError { return errors } -func (p *wireguardParser) getTypeByLine(line uint32) lineType { +func (p wireguardParser) getTypeByLine(line uint32) lineType { // Check if line is a comment if _, found := p.CommentLines[line]; found { return LineTypeComment @@ -168,13 +168,10 @@ func (p *wireguardParser) getTypeByLine(line uint32) lineType { // [Peer] // // This would return the section [Interface] -func (p *wireguardParser) getBelongingSectionByLine(line uint32) *wireguardSection { - // Create a copy - sections := append([]wireguardSection{}, p.Sections...) +func (p wireguardParser) getBelongingSectionByLine(line uint32) *wireguardSection { + for index := range p.Sections { + section := p.Sections[len(p.Sections)-index-1] - slices.Reverse(sections) - - for _, section := range sections { if section.StartLine <= line && section.Name != nil { return §ion }