From b95b36756ebfcdfaab6a403d93bc6514f3a3b2e2 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 25 Jan 2021 21:11:31 +0100 Subject: manager: pipeline UAPI requests This avoids the somewhat expensive pipe setup. Signed-off-by: Jason A. Donenfeld --- conf/parser.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'conf') diff --git a/conf/parser.go b/conf/parser.go index d26bdea4..dd0ee317 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -6,8 +6,10 @@ package conf import ( + "bufio" "encoding/base64" "encoding/hex" + "io" "net" "strconv" "strings" @@ -367,8 +369,7 @@ func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) { return nil, firstErr } -func FromUAPI(s string, existingConfig *Config) (*Config, error) { - lines := strings.Split(s, "\n") +func FromUAPI(reader io.Reader, existingConfig *Config) (*Config, error) { parserState := inInterfaceSection conf := Config{ Name: existingConfig.Name, @@ -380,9 +381,15 @@ func FromUAPI(s string, existingConfig *Config) (*Config, error) { }, } var peer *Peer - for _, line := range lines { + lineReader := bufio.NewReader(reader) + for { + line, err := lineReader.ReadString('\n') + if err != nil { + return nil, err + } + line = line[:len(line)-1] if len(line) == 0 { - continue + break } equals := strings.IndexByte(line, '=') if equals < 0 { -- cgit v1.2.3-59-g8ed1b