summaryrefslogtreecommitdiff
path: root/internal/wireguard/ini/ini.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/wireguard/ini/ini.go')
-rw-r--r--internal/wireguard/ini/ini.go42
1 files changed, 4 insertions, 38 deletions
diff --git a/internal/wireguard/ini/ini.go b/internal/wireguard/ini/ini.go
index 842928a..46c6f8b 100644
--- a/internal/wireguard/ini/ini.go
+++ b/internal/wireguard/ini/ini.go
@@ -7,7 +7,6 @@ package ini
import (
"errors"
"fmt"
- "slices"
"strings"
)
@@ -47,28 +46,6 @@ func keyValue(f string) (string, string, error) {
// OrderedKeys is a slice of strings that is used for an ordered map
type OrderedKeys []string
-func (ok *OrderedKeys) find(name string) int {
- if ok == nil {
- return -1
- }
- for i, v := range *ok {
- if v == name {
- return i
- }
- }
- return -1
-}
-
-// Remove removes a `name` from the OrderedKeys slice by finding the name
-// It is a no-op if the key does not exist
-func (ok *OrderedKeys) Remove(name string) {
- idx := ok.find(name)
- if idx == -1 {
- return
- }
- *ok = slices.Delete((*ok), idx, idx+1)
-}
-
// Section represents a single section within an ini file
// It consists of multiple key and values
type Section struct {
@@ -78,7 +55,7 @@ type Section struct {
// KeyValue gets a value for key `key`
// It returns an error if the key does not exist
-func (sec *Section) KeyValue(key string) (string, error) {
+func (sec *Section) keyValue(key string) (string, error) {
if v, ok := sec.keyValues[key]; ok {
return v, nil
}
@@ -96,7 +73,7 @@ func (sec *Section) newKeyValue(key string, value string) {
// AddOrReplaceKeyValue adds a key `key` with value `value`
// If the key already exists it modifies the value
func (sec *Section) AddOrReplaceKeyValue(key string, value string) {
- _, err := sec.KeyValue(key)
+ _, err := sec.keyValue(key)
if err == nil {
sec.keyValues[key] = value
return
@@ -108,7 +85,7 @@ func (sec *Section) AddOrReplaceKeyValue(key string, value string) {
// It returns an error if the key already exists
func (sec *Section) AddKeyValue(key string, value string) error {
// get an existing key
- _, err := sec.KeyValue(key)
+ _, err := sec.keyValue(key)
if err == nil {
return fmt.Errorf("key: '%s' already exists", key)
}
@@ -116,17 +93,6 @@ func (sec *Section) AddKeyValue(key string, value string) error {
return nil
}
-// RemoveKey removes a key `key` from the section
-// It returns an error if the key cannot be found
-func (sec *Section) RemoveKey(key string) (string, error) {
- if v, ok := sec.keyValues[key]; ok {
- sec.keys.Remove(key)
- delete(sec.keyValues, key)
- return v, nil
- }
- return "", fmt.Errorf("no key to remove with name: '%s'", key)
-}
-
// INI is the struct for a ini file
type INI struct {
sections map[string]*Section
@@ -172,7 +138,7 @@ func (i *INI) String() string {
out.WriteString(fmt.Sprintf("[%s]\n", s))
for _, k := range sec.keys {
- v, err := sec.KeyValue(k)
+ v, err := sec.keyValue(k)
if err != nil {
continue
}