1 files changed,
17 insertions(+),
11 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-07-23 14:51:52 +0300
Authored at:
2026-07-23 12:36:31 +0300
Change ID:
rpwqszsuolrkyrnvrsoumoxqlrwtqoxp
Parent:
9f9e365
M
internal/plumbing/ip/ip.go
··· 3 3 import ( 4 4 "context" 5 5 "errors" 6 + "fmt" 6 7 "io" 7 8 "net" 8 9 "net/http" ··· 17 18 func (Tool) Name() string { return "ip" } 18 19 func (Tool) Match(ctx *viye.Context) bool { return len(ctx.Path) == 1 && ctx.Path[0] == "ip" } 19 20 func (Tool) Execute(ctx *viye.Context) (string, error) { 20 - // TODO: if it's not possile to get public ip, report only local 21 + pip, perr := getPublicIP() 22 + lip, lerr := getLocalIP() 23 + if perr != nil && lerr != nil { 24 + return "", fmt.Errorf("couldn't resolve public and local ips") 25 + } 21 26 22 27 var buf strings.Builder 23 - buf.WriteString("| ") 28 + _, _ = buf.WriteString("| ") 24 29 25 - pip, err := getPublicIP() 26 - if err != nil { 27 - return "", err 30 + if perr == nil && lerr == nil { 31 + _, _ = buf.WriteString(pip) 32 + _, _ = buf.WriteString(" / ") 33 + _, _ = buf.WriteString(lip) 28 34 } 29 - _, _ = buf.WriteString(pip) 30 - _, _ = buf.WriteString(" / ") 31 35 32 - lip, err := getLocalIP() 33 - if err != nil { 34 - return "", err 36 + if perr == nil && lerr != nil { 37 + _, _ = buf.WriteString(pip) 35 38 } 36 - _, _ = buf.WriteString(lip) 39 + 40 + if lerr == nil && perr != nil { 41 + _, _ = buf.WriteString(pip) 42 + } 37 43 38 44 _ = buf.WriteByte('\n') 39 45 return buf.String(), nil