From 5be7e44150d31582e6d8577d48c842a421fa8ddc Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 31 Oct 2023 17:31:30 -0600 Subject: enable optional selector/host/port in extended gophermap lines fixes #11 --- gopher/gophermap/extended.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'gopher/gophermap') diff --git a/gopher/gophermap/extended.go b/gopher/gophermap/extended.go index 9692c51..8e48e99 100644 --- a/gopher/gophermap/extended.go +++ b/gopher/gophermap/extended.go @@ -108,16 +108,30 @@ outer: item = gopher.MapItem{Type: types.Status(line[0])} spl = strings.Split(line[1:], "\t") - if len(spl) != 4 { - return doc, InvalidLine(num) - } + item.Display = string(spl[0]) - item.Selector = string(spl[1]) - item.Hostname = string(spl[2]) - item.Port = string(spl[3]) + + if len(spl) == 1 { + item.Selector = location.Path + } else { + item.Selector = string(spl[1]) + } + + if len(spl) < 3 { + item.Hostname = location.Hostname() + } else { + item.Hostname = string(spl[2]) + } + + if len(spl) < 4 { + item.Port = location.Port() + } else { + item.Port = string(spl[3]) + } if _, err = strconv.Atoi(item.Port); err != nil { return doc, InvalidLine(num) } + doc.Lines = append(doc.Lines, item) next: -- cgit v1.2.3