update
This commit is contained in:
@@ -2,6 +2,9 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/minio/selfupdate"
|
||||
)
|
||||
|
||||
// App struct
|
||||
@@ -19,3 +22,19 @@ func NewApp() *App {
|
||||
func (a *App) OnStartup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
}
|
||||
|
||||
func (a *App) UpdateApp(url string) (broken bool, err error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
err = selfupdate.Apply(resp.Body, selfupdate.Options{})
|
||||
if err != nil {
|
||||
if rerr := selfupdate.RollbackError(err); rerr != nil {
|
||||
return true, rerr
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (a *App) StartServer(port int) (string, error) {
|
||||
func cmd(args ...string) (string, error) {
|
||||
cmdHelper, err := filepath.Abs("./cmd-helper")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmd := exec.Command(cmdHelper, "python", "./backend-python/main.py", strconv.Itoa(port))
|
||||
cmd := exec.Command(cmdHelper, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -19,15 +19,10 @@ func (a *App) StartServer(port int) (string, error) {
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {
|
||||
cmdHelper, err := filepath.Abs("./cmd-helper")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmd := exec.Command(cmdHelper, "python", "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
func (a *App) StartServer(port int) (string, error) {
|
||||
return cmd("python", "./backend-python/main.py", strconv.Itoa(port))
|
||||
}
|
||||
|
||||
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {
|
||||
return cmd("python", "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user