fix(wireguard): Improvements

This commit is contained in:
Myzel394 2024-08-14 11:47:42 +02:00
parent b08a5b68bf
commit d456f4a569
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -134,7 +134,7 @@ func (p *wireguardParser) parseFromString(input string) []lineError {
return errors return errors
} }
func (p *wireguardParser) getTypeByLine(line uint32) lineType { func (p wireguardParser) getTypeByLine(line uint32) lineType {
// Check if line is a comment // Check if line is a comment
if _, found := p.CommentLines[line]; found { if _, found := p.CommentLines[line]; found {
return LineTypeComment return LineTypeComment
@ -168,13 +168,10 @@ func (p *wireguardParser) getTypeByLine(line uint32) lineType {
// [Peer] // [Peer]
// //
// This would return the section [Interface] // This would return the section [Interface]
func (p *wireguardParser) getBelongingSectionByLine(line uint32) *wireguardSection { func (p wireguardParser) getBelongingSectionByLine(line uint32) *wireguardSection {
// Create a copy for index := range p.Sections {
sections := append([]wireguardSection{}, p.Sections...) section := p.Sections[len(p.Sections)-index-1]
slices.Reverse(sections)
for _, section := range sections {
if section.StartLine <= line && section.Name != nil { if section.StartLine <= line && section.Name != nil {
return &section return &section
} }