diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-31 17:31:30 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-31 17:31:30 -0600 |
commit | 5be7e44150d31582e6d8577d48c842a421fa8ddc (patch) | |
tree | 18f63f9bf87611840683c30fab289d89e4b19354 | |
parent | 4c817bf712e4ffed34fdd78375fcd7157cd14dc3 (diff) |
enable optional selector/host/port in extended gophermap lines
fixes #11
-rw-r--r-- | gopher/gophermap/extended.go | 26 |
1 files changed, 20 insertions, 6 deletions
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: |