1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 19:43:49 +08:00
go-cqhttp/global/update/update_windows.go
Ink33 144220a1da
enhance linter (#793)
* enhance linter

* fix golint
2021-04-05 15:14:56 +08:00

37 lines
673 B
Go

package update
import (
"archive/zip"
"bytes"
"fmt"
"io"
"net/http"
log "github.com/sirupsen/logrus"
)
// Update go-cqhttp自我更新
func Update(url string) {
resp, err := http.Get(url)
if err != nil {
log.Error("更新失败: ", err)
return
}
defer resp.Body.Close()
wc := WriteCounter{}
rsp, _ := io.ReadAll(io.TeeReader(resp.Body, &wc))
reader, _ := zip.NewReader(bytes.NewReader(rsp), resp.ContentLength)
file, err := reader.Open("go-cqhttp.exe")
if err != nil {
log.Error("更新失败!", err)
return
}
err, _ = FromStream(file)
fmt.Println()
if err != nil {
log.Error("更新失败!", err)
return
}
log.Info("更新完成!")
}