5 files changed,
13 insertions(+),
15 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-08-27 23:21:11 +0300
Authored at:
2026-08-27 23:16:30 +0300
Change ID:
qxlxwlqoyyqxnzmyqvznkptsoyxmrsqo
Parent:
686b345
M
internal/plumbing/curl/curl.go
··· 5 5 "fmt" 6 6 "os/exec" 7 7 "strings" 8 - "time" 9 8 10 9 "github.com/olexsmir/viye/internal/viye" 11 10 ) ··· 15 14 func (Tool) Name() string { return "curl" } 16 15 func (Tool) Match(c *viye.Context) bool { return c.Cmd == "curl" } 17 16 func (Tool) Execute(c *viye.Context) (string, error) { 18 - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 17 + ctx, cancel := context.WithTimeout(context.Background(), viye.Timeout) 19 18 defer cancel() 20 19 21 20 args := append([]string{"-sSL"}, c.Args...) ··· 25 24 26 25 output, err := cmd.CombinedOutput() 27 26 if err != nil && ctx.Err() == context.DeadlineExceeded { 28 - return "", fmt.Errorf("timeout: command exceeded 5s") 27 + return "", fmt.Errorf("timeout: command exceeded %s", viye.Timeout) 29 28 } 30 29 31 30 out := strings.ReplaceAll(string(output), "\r", "")
M
internal/plumbing/http/http.go
··· 7 7 "io" 8 8 "net/http" 9 9 "strings" 10 - "time" 11 10 12 11 "github.com/olexsmir/viye/internal/viye" 13 12 ) ··· 16 15 // : Header: Value 17 16 // : Header2: value 18 17 // : {"json": "body"} 19 - 20 -const timeout = 5 * time.Second 21 18 22 19 type Tool struct{} 23 20 ··· 36 33 return "", fmt.Errorf("body parsing error: %v", err) 37 34 } 38 35 39 - ctx, cancel := context.WithTimeout(context.Background(), timeout) 36 + ctx, cancel := context.WithTimeout(context.Background(), viye.Timeout) 40 37 defer cancel() 41 38 42 39 req, err := http.NewRequestWithContext(ctx, cmdToMethod(c.Cmd), c.Args[0], strings.NewReader(body)) ··· 47 44 req.Header.Set(header, value) 48 45 } 49 46 50 - resp, err := (&http.Client{Timeout: timeout}).Do(req) 47 + resp, err := (&http.Client{Timeout: viye.Timeout}).Do(req) 51 48 if err != nil { 52 49 return "", fmt.Errorf("failed to make a request: %v", err) 53 50 }
M
internal/plumbing/ip/ip.go
··· 8 8 "net" 9 9 "net/http" 10 10 "strings" 11 - "time" 12 11 13 12 "github.com/olexsmir/viye/internal/viye" 14 13 ) ··· 61 60 } 62 61 63 62 func getPublicIP() (string, error) { 64 - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 63 + ctx, cancel := context.WithTimeout(context.Background(), viye.Timeout) 65 64 defer cancel() 66 65 67 66 req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://ifconfig.me/ip", nil)
M
internal/plumbing/shell/shell.go
··· 9 9 "strconv" 10 10 "strings" 11 11 "syscall" 12 - "time" 13 12 14 13 "github.com/olexsmir/viye/internal/viye" 15 14 ) ··· 24 23 func (Tool) Execute(c *viye.Context) (string, error) { 25 24 switch { 26 25 case isCmd(c): 27 - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 26 + ctx, cancel := context.WithTimeout(context.Background(), viye.Timeout) 28 27 defer cancel() 29 28 30 29 cmd := exec.CommandContext(ctx, "sh", "-c", strings.Join(c.Args, " "))
M
internal/viye/viye.go
··· 5 5 "fmt" 6 6 "io" 7 7 "os" 8 + "time" 8 9 ) 9 10 10 -const Version = "0.0.1-alpha" 11 +var ErrToolNotFound = errors.New("tool not found") 11 12 12 -var ErrPlumbingNotFound = errors.New("tool not found") 13 +const ( 14 + Version = "0.0.1-alpha" 15 + Timeout = 5 * time.Second 16 +) 13 17 14 18 type Context struct { 15 19 Dir string // working directory ··· 89 93 return tool.Execute(ctx) 90 94 } 91 95 } 92 - return "", ErrPlumbingNotFound 96 + return "", ErrToolNotFound 93 97 } 94 98 95 99 func expandEnv(s string) string {