forked from charmbracelet/mods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.go
More file actions
33 lines (29 loc) · 669 Bytes
/
Copy pathload.go
File metadata and controls
33 lines (29 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"io"
"net/http"
"os"
"strings"
)
func loadMsg(msg string) (string, error) {
if strings.HasPrefix(msg, "https://") || strings.HasPrefix(msg, "http://") {
resp, err := http.Get(msg) //nolint:gosec,noctx
if err != nil {
return "", err //nolint:wrapcheck
}
defer func() { _ = resp.Body.Close() }()
bts, err := io.ReadAll(resp.Body)
if err != nil {
return "", err //nolint:wrapcheck
}
return string(bts), nil
}
if strings.HasPrefix(msg, "file://") {
bts, err := os.ReadFile(strings.TrimPrefix(msg, "file://"))
if err != nil {
return "", err //nolint:wrapcheck
}
return string(bts), nil
}
return msg, nil
}