mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-09-19 20:15:59 +08:00
30 lines
583 B
Go
30 lines
583 B
Go
package updater
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
mihomoHttp "github.com/metacubex/mihomo/component/http"
|
|
)
|
|
|
|
const defaultHttpTimeout = time.Second * 90
|
|
|
|
func downloadForBytes(url string) ([]byte, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), defaultHttpTimeout)
|
|
defer cancel()
|
|
resp, err := mihomoHttp.HttpRequest(ctx, url, http.MethodGet, nil, nil)
|
|
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)
|
|
}
|