From a23c76305a07f5ff1630924f42fd8cb002a6a661 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Sat, 1 Aug 2020 17:12:09 +0800 Subject: [PATCH 1/5] Automatic update bee every day Backup only when content changes Fix the version --- cmd/commands/version/version.go | 2 +- internal/app/module/beegopro/config.go | 2 +- internal/app/module/beegopro/render.go | 39 ++++++++++++-- internal/app/module/beegopro/util.go | 70 +++++++++++++++++--------- main.go | 1 + utils/utils.go | 64 +++++++++++++++++++++++ 6 files changed, 148 insertions(+), 30 deletions(-) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 4eebd9f..a1ce710 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -57,7 +57,7 @@ Prints the current Bee, Beego and Go version alongside the platform information. } var outputFormat string -const version = "1.11.0" +const version = "1.12.0" func init() { fs := flag.NewFlagSet("version", flag.ContinueOnError) diff --git a/internal/app/module/beegopro/config.go b/internal/app/module/beegopro/config.go index f4854fe..7fbdc2c 100644 --- a/internal/app/module/beegopro/config.go +++ b/internal/app/module/beegopro/config.go @@ -5,7 +5,7 @@ import ( beeLogger "github.com/beego/bee/logger" "io/ioutil" ) - +var CompareExcept = []string{"@BeeGenerateTime"} func (c *Container) GenConfig() { if utils.IsExist(c.BeegoProFile) { beeLogger.Log.Fatalf("beego pro toml exist") diff --git a/internal/app/module/beegopro/render.go b/internal/app/module/beegopro/render.go index f2e49c3..7ca97ae 100644 --- a/internal/app/module/beegopro/render.go +++ b/internal/app/module/beegopro/render.go @@ -6,6 +6,9 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/flosch/pongo2" "github.com/smartwalle/pongo2render" + "go/format" + "io/ioutil" + "os" "path" "path/filepath" ) @@ -114,10 +117,36 @@ func (r *RenderFile) Exec(name string) { beeLogger.Log.Fatalf("Could not create the %s render tmpl: %s", name, err) return } - err = r.write(r.FlushFile, buf) - if err != nil { - beeLogger.Log.Fatalf("Could not create file: %s", err) - return + _, err = os.Stat(r.Descriptor.DstPath) + var orgContent []byte + if err == nil { + if org, err := os.OpenFile(r.Descriptor.DstPath, os.O_RDONLY, 0666); err == nil { + orgContent,_ = ioutil.ReadAll(org) + org.Close() + } else { + beeLogger.Log.Infof("file err %s", err) + } + } + // Replace or create when content changes + output := []byte(buf) + ext := filepath.Ext(r.FlushFile) + if r.Option.EnableFormat && ext == ".go" { + // format code + var bts []byte + bts, err = format.Source([]byte(buf)) + if err != nil { + beeLogger.Log.Warnf("format buf error %s", err.Error()) + } + output = bts + } + + if FileContentChange(orgContent,output,GetSeg(ext)) { + err = r.write(r.FlushFile, output) + if err != nil { + beeLogger.Log.Fatalf("Could not create file: %s", err) + return + } + beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName) } - beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName) } + diff --git a/internal/app/module/beegopro/util.go b/internal/app/module/beegopro/util.go index 646ffb2..bfef1db 100644 --- a/internal/app/module/beegopro/util.go +++ b/internal/app/module/beegopro/util.go @@ -1,11 +1,11 @@ package beegopro import ( + "crypto/md5" "errors" "fmt" "github.com/beego/bee/internal/pkg/utils" beeLogger "github.com/beego/bee/logger" - "go/format" "io/ioutil" "os" "path" @@ -15,12 +15,12 @@ import ( ) // write to file -func (c *RenderFile) write(filename string, buf string) (err error) { +func (c *RenderFile) write(filename string, buf []byte) (err error) { if utils.IsExist(filename) && !isNeedOverwrite(filename) { return } - filePath := path.Dir(filename) + filePath := filepath.Dir(filename) err = createPath(filePath) if err != nil { err = errors.New("write create path " + err.Error()) @@ -37,7 +37,7 @@ func (c *RenderFile) write(filename string, buf string) (err error) { name := path.Base(filename) if utils.IsExist(filename) { - bakName := fmt.Sprintf("%s/%s.%s.bak", filePathBak, name, time.Now().Format("2006.01.02.15.04.05")) + bakName := fmt.Sprintf("%s/%s.%s.bak", filePathBak, filepath.Base(name), time.Now().Format("2006.01.02.15.04.05")) beeLogger.Log.Infof("bak file '%s'", bakName) if err := os.Rename(filename, bakName); err != nil { err = errors.New("file is bak error, path is " + bakName) @@ -57,20 +57,7 @@ func (c *RenderFile) write(filename string, buf string) (err error) { return } - output := []byte(buf) - - if c.Option.EnableFormat && filepath.Ext(filename) == ".go" { - // format code - var bts []byte - bts, err = format.Source([]byte(buf)) - if err != nil { - err = errors.New("format buf error " + err.Error()) - return - } - output = bts - } - - err = ioutil.WriteFile(filename, output, 0644) + err = ioutil.WriteFile(filename, buf, 0644) if err != nil { err = errors.New("write write file " + err.Error()) return @@ -79,11 +66,7 @@ func (c *RenderFile) write(filename string, buf string) (err error) { } func isNeedOverwrite(fileName string) (flag bool) { - seg := "//" - ext := filepath.Ext(fileName) - if ext == ".sql" { - seg = "--" - } + seg := GetSeg(filepath.Ext(fileName)) f, err := os.Open(fileName) if err != nil { @@ -188,3 +171,44 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) { } return } + +func FileContentChange(org,new []byte, seg string) bool { + if len(org) == 0 { + return true + } + orgContent := GetFilterContent(string(org),seg) + newContent := GetFilterContent(string(new),seg) + orgMd5 := md5.Sum([]byte(orgContent)) + newMd5:= md5.Sum([]byte(newContent)) + if orgMd5 != newMd5 { + return true + } + beeLogger.Log.Infof("File has no change in the content") + return false +} + +func GetFilterContent(content string, seg string) string { + res := "" + for _, s := range strings.Split(content, "\n") { + s = strings.TrimSpace(strings.TrimPrefix(s, seg)) + var have = false + for _,except := range CompareExcept{ + if strings.HasPrefix(s, except) { + have = true + } + } + if !have { + res += s + } + } + return res +} + +func GetSeg(ext string) string { + switch ext { + case ".sql": + return "--" + default: + return "//" + } +} diff --git a/main.go b/main.go index 851b199..112d6c0 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( ) func main() { + utils.UpdateBee() flag.Usage = cmd.Usage flag.Parse() log.SetFlags(0) diff --git a/utils/utils.go b/utils/utils.go index eedd57a..969e902 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -24,6 +24,7 @@ import ( "path/filepath" "regexp" "runtime" + "strconv" "strings" "text/template" "time" @@ -31,6 +32,7 @@ import ( beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" + "github.com/beego/bee/internal/pkg/system" ) func GetBeeWorkPath() string { @@ -463,3 +465,65 @@ func IsGOMODULE() bool { } return false } + +func UpdateBee() { + cmd := exec.Command("go", "version") + cmd.Output() + if cmd.Process == nil || cmd.Process.Pid <= 0 { + beeLogger.Log.Warn("There is no go environment") + return + } + path := system.BeegoHome + fp := path + "/.updateBee" + timeNow := time.Now().Unix() + var timeOld int64 + if IsExist(fp) { + oldContent, err := ioutil.ReadFile(fp) + if err != nil { + beeLogger.Log.Warnf("read file err: %s", err) + } + timeOld, _ = strconv.ParseInt(string(oldContent), 10, 64) + } else { + if cf, err := os.OpenFile(fp, os.O_CREATE, 0644); err == nil { + cf.Close() + } else { + beeLogger.Log.Warnf("Create file err: %s", err) + } + } + if timeNow-timeOld > 24*60*60 { + if w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC, 0644); err == nil { + defer w.Close() + timeNowStr := strconv.FormatInt(timeNow, 10) + if _, err := w.WriteString(timeNowStr); err != nil { + beeLogger.Log.Warnf("Update file err: %s", err) + } + beeLogger.Log.Info("Updating bee") + goGetBee() + } else { + beeLogger.Log.Warnf("Update Bee file err: %s", err) + } + } +} + +func goGetBee() { + beePath := "github.com/beego/bee" + done := make(chan int, 1) + go func() { + cmd := exec.Command("go", "get", "-u", beePath) + output, err := cmd.Output() + if err != nil { + beeLogger.Log.Warnf("Update Bee err: %s", err) + beeLogger.Log.Warnf("Update Bee err: %s", output) + } + beeLogger.Log.Infof("Bee was updated successfully %s", output) + done <- 1 + }() + // wait 30 second + select { + case <-done: + return + case <-time.After(time.Second * 30): + beeLogger.Log.Warn("Update Bee timeout! The next automatic update will be in 24 hours.") + beeLogger.Log.Warn("Or you can update it yourself with `go get -u github.com/beego/bee`") + } +} From e539c34ea0a96a16376cc295ef8e0427d4591415 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Sun, 2 Aug 2020 16:17:02 +0800 Subject: [PATCH 2/5] add cmd 'bee update' to update self just notice once a day if there is a new version --- cmd/bee.go | 1 + cmd/commands/command.go | 1 + cmd/commands/update/update.go | 38 ++++++++++ cmd/commands/version/version.go | 6 +- config/conf.go | 9 ++- internal/app/module/beegopro/render.go | 14 ++-- internal/app/module/beegopro/util.go | 7 +- main.go | 2 +- utils/utils.go | 99 ++++++++++++++------------ 9 files changed, 119 insertions(+), 58 deletions(-) create mode 100644 cmd/commands/update/update.go diff --git a/cmd/bee.go b/cmd/bee.go index a6c2c80..8a4f9ec 100644 --- a/cmd/bee.go +++ b/cmd/bee.go @@ -31,6 +31,7 @@ import ( _ "github.com/beego/bee/cmd/commands/rs" _ "github.com/beego/bee/cmd/commands/run" _ "github.com/beego/bee/cmd/commands/server" + _ "github.com/beego/bee/cmd/commands/update" _ "github.com/beego/bee/cmd/commands/version" "github.com/beego/bee/utils" ) diff --git a/cmd/commands/command.go b/cmd/commands/command.go index cab663f..95a1891 100644 --- a/cmd/commands/command.go +++ b/cmd/commands/command.go @@ -65,6 +65,7 @@ func (c *Command) Out() io.Writer { if c.output != nil { return *c.output } + return colors.NewColorWriter(os.Stderr) } diff --git a/cmd/commands/update/update.go b/cmd/commands/update/update.go new file mode 100644 index 0000000..3e5a87a --- /dev/null +++ b/cmd/commands/update/update.go @@ -0,0 +1,38 @@ +package update + +import ( + "flag" + "os" + "os/exec" + + "github.com/beego/bee/cmd/commands" + "github.com/beego/bee/config" + beeLogger "github.com/beego/bee/logger" +) + +var CmdUpdate = &commands.Command{ + UsageLine: "update", + Short: "Update Bee", + Long: ` +Automatic run command "go get -u github.com/beego/bee" for selfupdate +`, + Run: updateBee, +} + +func init() { + fs := flag.NewFlagSet("update", flag.ContinueOnError) + CmdUpdate.Flag = *fs + commands.AvailableCommands = append(commands.AvailableCommands, CmdUpdate) +} + +func updateBee(cmd *commands.Command, args []string) int { + beeLogger.Log.Info("Updating") + beePath := config.GitRemotePath + cmdUp := exec.Command("go", "get", "-u", beePath) + cmdUp.Stdout = os.Stdout + cmdUp.Stderr = os.Stderr + if err := cmdUp.Run(); err != nil { + beeLogger.Log.Warnf("Run cmd err:%s",err) + } + return 0 +} diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index a1ce710..32862a7 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -14,11 +14,13 @@ import ( "runtime" "strings" + "gopkg.in/yaml.v2" + "github.com/beego/bee/cmd/commands" + "github.com/beego/bee/config" beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" "github.com/beego/bee/utils" - "gopkg.in/yaml.v2" ) const verboseVersionBanner string = `%s%s______ @@ -57,7 +59,7 @@ Prints the current Bee, Beego and Go version alongside the platform information. } var outputFormat string -const version = "1.12.0" +const version = config.Version func init() { fs := flag.NewFlagSet("version", flag.ContinueOnError) diff --git a/config/conf.go b/config/conf.go index 32bdf2c..e0603e9 100644 --- a/config/conf.go +++ b/config/conf.go @@ -19,12 +19,19 @@ import ( "os" "path/filepath" - beeLogger "github.com/beego/bee/logger" "gopkg.in/yaml.v2" + + beeLogger "github.com/beego/bee/logger" ) const confVer = 0 +const ( + Version = "1.12.0" + GitRemotePath = "github.com/beego/bee" +) + + var Conf = struct { Version int WatchExts []string `json:"watch_ext" yaml:"watch_ext"` diff --git a/internal/app/module/beegopro/render.go b/internal/app/module/beegopro/render.go index 7ca97ae..7ca1464 100644 --- a/internal/app/module/beegopro/render.go +++ b/internal/app/module/beegopro/render.go @@ -1,16 +1,18 @@ package beegopro import ( - "github.com/beego/bee/internal/pkg/system" - beeLogger "github.com/beego/bee/logger" - "github.com/davecgh/go-spew/spew" - "github.com/flosch/pongo2" - "github.com/smartwalle/pongo2render" "go/format" "io/ioutil" "os" "path" "path/filepath" + + "github.com/davecgh/go-spew/spew" + "github.com/flosch/pongo2" + "github.com/smartwalle/pongo2render" + + "github.com/beego/bee/internal/pkg/system" + beeLogger "github.com/beego/bee/logger" ) // render @@ -140,7 +142,7 @@ func (r *RenderFile) Exec(name string) { output = bts } - if FileContentChange(orgContent,output,GetSeg(ext)) { + if FileContentChange(orgContent, output, GetSeg(ext)) { err = r.write(r.FlushFile, output) if err != nil { beeLogger.Log.Fatalf("Could not create file: %s", err) diff --git a/internal/app/module/beegopro/util.go b/internal/app/module/beegopro/util.go index bfef1db..604e404 100644 --- a/internal/app/module/beegopro/util.go +++ b/internal/app/module/beegopro/util.go @@ -4,14 +4,15 @@ import ( "crypto/md5" "errors" "fmt" - "github.com/beego/bee/internal/pkg/utils" - beeLogger "github.com/beego/bee/logger" "io/ioutil" "os" "path" "path/filepath" "strings" "time" + + "github.com/beego/bee/internal/pkg/utils" + beeLogger "github.com/beego/bee/logger" ) // write to file @@ -191,7 +192,7 @@ func GetFilterContent(content string, seg string) string { res := "" for _, s := range strings.Split(content, "\n") { s = strings.TrimSpace(strings.TrimPrefix(s, seg)) - var have = false + var have bool for _,except := range CompareExcept{ if strings.HasPrefix(s, except) { have = true diff --git a/main.go b/main.go index 112d6c0..251ee51 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( ) func main() { - utils.UpdateBee() + utils.NoticeUpdateBee() flag.Usage = cmd.Usage flag.Parse() log.SetFlags(0) diff --git a/utils/utils.go b/utils/utils.go index 969e902..b2056e4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -30,9 +30,12 @@ import ( "time" "unicode" + "github.com/beego/bee/config" + "github.com/beego/bee/internal/pkg/git" + + "github.com/beego/bee/internal/pkg/system" beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" - "github.com/beego/bee/internal/pkg/system" ) func GetBeeWorkPath() string { @@ -466,64 +469,70 @@ func IsGOMODULE() bool { return false } -func UpdateBee() { +func NoticeUpdateBee() { cmd := exec.Command("go", "version") cmd.Output() if cmd.Process == nil || cmd.Process.Pid <= 0 { beeLogger.Log.Warn("There is no go environment") return } - path := system.BeegoHome - fp := path + "/.updateBee" + beeHome := system.BeegoHome + fp := beeHome + "/.noticeUpdateBee" timeNow := time.Now().Unix() var timeOld int64 - if IsExist(fp) { - oldContent, err := ioutil.ReadFile(fp) + if !IsExist(fp) { + f, err := os.Create(fp) if err != nil { - beeLogger.Log.Warnf("read file err: %s", err) - } - timeOld, _ = strconv.ParseInt(string(oldContent), 10, 64) - } else { - if cf, err := os.OpenFile(fp, os.O_CREATE, 0644); err == nil { - cf.Close() - } else { - beeLogger.Log.Warnf("Create file err: %s", err) + beeLogger.Log.Warnf("Create noticeUpdateBee file err: %s", err) + return } + defer f.Close() } - if timeNow-timeOld > 24*60*60 { - if w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC, 0644); err == nil { - defer w.Close() - timeNowStr := strconv.FormatInt(timeNow, 10) - if _, err := w.WriteString(timeNowStr); err != nil { - beeLogger.Log.Warnf("Update file err: %s", err) - } - beeLogger.Log.Info("Updating bee") - goGetBee() - } else { - beeLogger.Log.Warnf("Update Bee file err: %s", err) - } + oldContent, err := ioutil.ReadFile(fp) + if err != nil { + beeLogger.Log.Warnf("Read noticeUpdateBee file err: %s", err) + return } + timeOld, _ = strconv.ParseInt(string(oldContent), 10, 64) + if timeNow-timeOld < 24*60*60 { + return + } + w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + beeLogger.Log.Warnf("Open noticeUpdateBee file err: %s", err) + return + } + defer w.Close() + timeNowStr := strconv.FormatInt(timeNow, 10) + if _, err := w.WriteString(timeNowStr); err != nil { + beeLogger.Log.Warnf("Update noticeUpdateBee file err: %s", err) + return + } + newVersion() } -func goGetBee() { - beePath := "github.com/beego/bee" - done := make(chan int, 1) - go func() { - cmd := exec.Command("go", "get", "-u", beePath) - output, err := cmd.Output() - if err != nil { - beeLogger.Log.Warnf("Update Bee err: %s", err) - beeLogger.Log.Warnf("Update Bee err: %s", output) - } - beeLogger.Log.Infof("Bee was updated successfully %s", output) - done <- 1 - }() - // wait 30 second - select { - case <-done: +func newVersion() { + workPath := GetBeeWorkPath() + repo, err := git.OpenRepository(workPath) + if err != nil { + beeLogger.Log.Fatalf("Fail to open repository, err: %s", err) return - case <-time.After(time.Second * 30): - beeLogger.Log.Warn("Update Bee timeout! The next automatic update will be in 24 hours.") - beeLogger.Log.Warn("Or you can update it yourself with `go get -u github.com/beego/bee`") + } + tags, err := repo.GetTags() + if err != nil { + beeLogger.Log.Fatalf("Fail to get tags, err: %s", err) + return + } + // v1.12.0 | V_1.12.0 => 1.12.0 + re, _ := regexp.Compile(`[0-9.]+`) + var versionLast string + versionList := re.FindStringSubmatch(tags[0]) + if len(versionList) >= 1 { + versionLast = versionList[0] + } + versionNow := config.Version + if versionNow != versionLast { + beeLogger.Log.Warnf("Update available %s ==> %s", versionNow, versionLast) + beeLogger.Log.Warn("Run `bee update` to update") } } From 40a90af5be067fd396ed46bf9ba25668fdfb1a7c Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Sun, 2 Aug 2020 17:00:29 +0800 Subject: [PATCH 3/5] fix the bee path --- utils/utils.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index b2056e4..7ecb0b6 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -512,7 +512,10 @@ func NoticeUpdateBee() { } func newVersion() { - workPath := GetBeeWorkPath() + hs, _, workPath := SearchGOPATHs(config.GitRemotePath) + if hs == false { + beeLogger.Log.Warn("Fail to open repository") + } repo, err := git.OpenRepository(workPath) if err != nil { beeLogger.Log.Fatalf("Fail to open repository, err: %s", err) From 07fa523da9ce0454275b7d3fdc1643578d527249 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Sun, 2 Aug 2020 23:02:12 +0800 Subject: [PATCH 4/5] get bee latest version by 'https://api.github.com/repos/beego/bee/tags' --- utils/utils.go | 68 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 7ecb0b6..a940670 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -16,8 +16,10 @@ package utils import ( "bytes" + "encoding/json" "fmt" "io/ioutil" + "net/http" "os" "os/exec" "path" @@ -31,13 +33,15 @@ import ( "unicode" "github.com/beego/bee/config" - "github.com/beego/bee/internal/pkg/git" - "github.com/beego/bee/internal/pkg/system" beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" ) +type tagName struct { + Name string `json:"name"` +} + func GetBeeWorkPath() string { curpath, err := os.Getwd() if err != nil { @@ -508,34 +512,44 @@ func NoticeUpdateBee() { beeLogger.Log.Warnf("Update noticeUpdateBee file err: %s", err) return } - newVersion() -} - -func newVersion() { - hs, _, workPath := SearchGOPATHs(config.GitRemotePath) - if hs == false { - beeLogger.Log.Warn("Fail to open repository") - } - repo, err := git.OpenRepository(workPath) - if err != nil { - beeLogger.Log.Fatalf("Fail to open repository, err: %s", err) - return - } - tags, err := repo.GetTags() - if err != nil { - beeLogger.Log.Fatalf("Fail to get tags, err: %s", err) - return - } - // v1.12.0 | V_1.12.0 => 1.12.0 - re, _ := regexp.Compile(`[0-9.]+`) - var versionLast string - versionList := re.FindStringSubmatch(tags[0]) - if len(versionList) >= 1 { - versionLast = versionList[0] - } + beeLogger.Log.Info("Getting bee latest version...") + versionLast := BeeLastVersion() versionNow := config.Version + if versionLast == ""{ + beeLogger.Log.Warn("Get latest version err") + return + } if versionNow != versionLast { beeLogger.Log.Warnf("Update available %s ==> %s", versionNow, versionLast) beeLogger.Log.Warn("Run `bee update` to update") } + beeLogger.Log.Info("Your bee are up to date") +} + +func BeeLastVersion() (version string) { + var url = "https://api.github.com/repos/beego/bee/tags" + resp, err := http.Get(url) + if err != nil { + beeLogger.Log.Warnf("Get bee tags from github error: %s", err) + return + } + defer resp.Body.Close() + bodyContent, _ := ioutil.ReadAll(resp.Body) + var tags []tagName + if err = json.Unmarshal(bodyContent, &tags); err != nil { + beeLogger.Log.Warnf("Unmarshal tags body error: %s", err) + return + } + if len(tags) < 1 { + beeLogger.Log.Warn("There is no tags!") + return + } + last := tags[0] + re, _ := regexp.Compile(`[0-9.]+`) + versionList := re.FindStringSubmatch(last.Name) + if len(versionList) > 0 { + return versionList[0] + } + beeLogger.Log.Warn("There is no tags!") + return } From 413f4ef12944a546141ca136aaa7744c2c3e2f32 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Mon, 10 Aug 2020 22:46:29 +0800 Subject: [PATCH 5/5] make .beego dir if don`t exist --- utils/utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index a940670..e9656dc 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -481,6 +481,12 @@ func NoticeUpdateBee() { return } beeHome := system.BeegoHome + if !IsExist(beeHome) { + if err := os.MkdirAll(beeHome, 0755); err != nil { + beeLogger.Log.Fatalf("Could not create the directory: %s", err) + return + } + } fp := beeHome + "/.noticeUpdateBee" timeNow := time.Now().Unix() var timeOld int64