1
0
mirror of https://github.com/beego/bee.git synced 2025-06-11 03:10:40 +00:00

接收不同git仓库

This commit is contained in:
王厚伟
2021-01-08 02:09:11 +08:00
parent f150956981
commit a44ef93f99
3 changed files with 32 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package beegopro
import (
"fmt"
"io/ioutil"
"strings"
"sync"
"time"
@ -15,6 +16,8 @@ import (
"github.com/spf13/viper"
)
var GitRemotePath utils.DocValue
const MDateFormat = "20060102_150405"
var DefaultBeegoPro = &Container{
@ -30,9 +33,10 @@ var DefaultBeegoPro = &Container{
ApiPrefix: "/api",
EnableModule: nil,
Models: make(map[string]TextModel),
GitRemotePath: "https://github.com/beego/beego-pro.git",
Branch: "master",
GitLocalPath: system.BeegoHome + "/beego-pro",
GitRemotePath: "",
//GitRemotePath: "https://github.com/beego/beego-pro.git",
Branch: "master",
//GitLocalPath: system.BeegoHome + "/beego-pro",
EnableFormat: true,
SourceGen: "text",
EnableGitPull: true,
@ -72,7 +76,6 @@ func (c *Container) initUserOption() {
beeLogger.Log.Fatalf("read beego pro config content, err: %s", err.Error())
return
}
err = viper.Unmarshal(&c.UserOption)
if err != nil {
beeLogger.Log.Fatalf("beego pro config unmarshal error, err: %s", err.Error())
@ -100,10 +103,10 @@ func (c *Container) initUserOption() {
if c.UserOption.Debug {
fmt.Println("c.modules", c.EnableModules)
}
}
func (c *Container) initTemplateOption() {
c.GetLocalPath()
if c.UserOption.EnableGitPull && (c.GenerateTimeUnix-c.Timestamp.GitCacheLastRefresh > c.UserOption.RefreshGitTime) {
err := git.CloneORPullRepo(c.UserOption.GitRemotePath, c.UserOption.GitLocalPath)
if err != nil {
@ -225,4 +228,24 @@ func (c *Container) InitToml() {
return
}
beeLogger.Log.Success("Successfully created file beegopro.toml")
}
}
//form https://github.com/beego/beego-pro.git
//get beego/beego-pro
func (c *Container) GetLocalPath() {
if c.UserOption.GitLocalPath != "" {
return
}
if GitRemotePath != "" {
c.UserOption.GitRemotePath = GitRemotePath.String()
}
if c.UserOption.GitRemotePath == "" {
c.UserOption.GitRemotePath = "https://github.com/beego/beego-pro.git"
}
url := c.UserOption.GitRemotePath
url = strings.TrimPrefix(url, "http://")
url = strings.TrimPrefix(url, "https://")
url = strings.TrimRight(url, ".git")
index := strings.Index(url, "/")
c.UserOption.GitLocalPath = system.BeegoHome + url[index:]
}