This commit is contained in:
admju
2024-09-04 07:11:13 +00:00
parent d12d3e31bf
commit 48301bf82e
17 changed files with 210 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import (
"os"
"errors"
"io"
"path/filepath"
"gopkg.in/yaml.v2"
log "oc-deploy/log_wrapper"
)
@@ -14,6 +15,8 @@ type versionInput struct {
Version string `yaml:"version"`
}
var OFFLINE_DIR string = "../offline"
func GetFromFile(fileversion string) (string, error) {
fin, err := os.Open(fileversion)
if err != nil {
@@ -28,7 +31,10 @@ func GetFromFile(fileversion string) (string, error) {
var objmap versionInput
yaml.Unmarshal(byteValue, &objmap)
err = yaml.Unmarshal(byteValue, &objmap)
if err != nil {
return "", err
}
return objmap.Version, nil
}
@@ -45,7 +51,8 @@ func Get(version string) (string, error) {
version2 = versionLatest
}
src := fmt.Sprintf("../offline/oc_%s.yml", version2)
ficversion := fmt.Sprintf("oc_%s.yml", version2)
src := filepath.Join(OFFLINE_DIR, ficversion)
if _, err := os.Stat(src); err != nil {
log.Log().Debug().Msg(err.Error())
return "", errors.New("Version non disponible")
@@ -56,9 +63,10 @@ func Get(version string) (string, error) {
// readLatestFile : Lit le numéro de la version dans le fichier lastest.yml
func readLatestFile() (string, error) {
src := "../offline/latest.yml"
src := filepath.Join(OFFLINE_DIR, "latest.yml")
fin, err := os.Open(src)
if err != nil {
return "", err
}
@@ -71,7 +79,11 @@ func readLatestFile() (string, error) {
var objmap versionInput
yaml.Unmarshal(byteValue, &objmap)
err = yaml.Unmarshal(byteValue, &objmap)
if err != nil {
return "", err
}
return objmap.Version, nil
}