1
0
mirror of https://github.com/MetaCubeX/mihomo.git synced 2025-09-19 20:15:59 +08:00
Files
mihomo/component/updater/utils.go

30 lines
583 B
Go
Raw Normal View History

package updater
import (
2024-05-17 11:49:09 +08:00
"context"
"io"
2024-05-17 11:49:09 +08:00
"net/http"
"os"
"time"
mihomoHttp "github.com/metacubex/mihomo/component/http"
)
2024-09-22 13:57:57 +08:00
const defaultHttpTimeout = time.Second * 90
2024-05-17 11:49:09 +08:00
func downloadForBytes(url string) ([]byte, error) {
2024-09-22 13:57:57 +08:00
ctx, cancel := context.WithTimeout(context.Background(), defaultHttpTimeout)
2024-05-17 11:49:09 +08:00
defer cancel()
2024-09-09 16:08:48 +08:00
resp, err := mihomoHttp.HttpRequest(ctx, url, http.MethodGet, nil, nil)
2024-05-17 11:49:09 +08:00
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func saveFile(bytes []byte, path string) error {
return os.WriteFile(path, bytes, 0o644)
}