Skip to content

Commit

Permalink
Merge pull request #822 from flycash/develop
Browse files Browse the repository at this point in the history
Prepare release v2.0.3
  • Loading branch information
flycash authored May 23, 2022
2 parents 457c2f7 + 97df75a commit a75a0c8
Show file tree
Hide file tree
Showing 25 changed files with 1,976 additions and 140 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Go

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ script:
- cd $(dirname `dirname $(pwd)`)/beego/bee
- export GO111MODULE="on"
- go mod download
- go test -coverprofile=coverage.txt -covermode=atomic ./...
- find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s
- go list ./... | grep -v /vendor/ | grep -v /pkg/mod/
- go vet $(go list ./... | grep -v /vendor/ | grep -v /pkg/mod/ )
Expand Down
244 changes: 146 additions & 98 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/bee.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func Usage() {
func Help(args []string) {
if len(args) == 0 {
Usage()
return
}
if len(args) != 1 {
utils.PrintErrorAndExit("Too many arguments", ErrorTemplate)
Expand Down
10 changes: 7 additions & 3 deletions cmd/commands/api/apiapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ import (
)
func main() {
orm.RegisterDataBase("default", "{{.DriverName}}", beego.AppConfig.String("sqlconn"))
sqlConn,err := beego.AppConfig.String("sqlconn")
if err != nil {
beeLogger.Log.Fatal("%s", err)
}
orm.RegisterDataBase("default", "{{.DriverName}}", sqlConn)
if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
Expand Down Expand Up @@ -575,14 +579,14 @@ func createAPI(cmd *commands.Command, args []string) int {
var packPath string
var err error
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
beeLogger.Log.Info("Generate api project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
}
} else {
beeLogger.Log.Info("generate api project support go modules.")
beeLogger.Log.Info("Generate api project support go modules.")
appPath = path.Join(utils.GetBeeWorkPath(), args[0])
packPath = args[0]
if beegoVersion.String() == `` {
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/beefix/fix1To2.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func fix1To2() int {
beeLogger.Log.Info("Upgrading the application...")

cmdStr := `go get -u github.com/beego/beego/v2@develop`
cmdStr := `go get -u github.com/beego/beego/v2@master`
err := runShell(cmdStr)
if err != nil {
beeLogger.Log.Error(err.Error())
Expand Down
3 changes: 3 additions & 0 deletions cmd/commands/beegopro/beegopro.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
CmdBeegoPro.Flag.Var(&beegopro.SQL, "sql", "sql file path")
CmdBeegoPro.Flag.Var(&beegopro.SQLMode, "sqlmode", "sql mode")
CmdBeegoPro.Flag.Var(&beegopro.SQLModePath, "sqlpath", "sql mode path")
CmdBeegoPro.Flag.Var(&beegopro.GitRemotePath, "url", "git remote path")
commands.AvailableCommands = append(commands.AvailableCommands, CmdBeegoPro)
}

Expand All @@ -48,6 +49,8 @@ func BeegoPro(cmd *commands.Command, args []string) int {
switch gcmd {
case "gen":
beegopro.DefaultBeegoPro.Run()
case "toml":
beegopro.DefaultBeegoPro.InitToml()
case "config":
beegopro.DefaultBeegoPro.GenConfig()
case "migration":
Expand Down
4 changes: 1 addition & 3 deletions cmd/commands/dockerize/dockerize.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ func dockerizeApp(cmd *commands.Command, args []string) int {
// In case of multiple ports to expose inside the container,
// replace all the commas with whitespaces.
// See the verb EXPOSE in the Docker documentation.
if strings.Contains(expose, ",") {
expose = strings.Replace(expose, ",", " ", -1)
}
expose = strings.Replace(expose, ",", " ", -1)

_, entrypoint := path.Split(appdir)
dockerfile := Dockerfile{
Expand Down
25 changes: 25 additions & 0 deletions cmd/commands/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ var CmdGenerate = &commands.Command{
$ bee generate docs
▶ {{"To generate swagger doc file:"|bold}}
$ bee generate routers [-ctrlDir=/path/to/controller/directory] [-routersFile=/path/to/routers/file.go] [-routersPkg=myPackage]
▶ {{"To generate a test case:"|bold}}
$ bee generate test [routerfile]
Expand All @@ -72,6 +76,15 @@ func init() {
CmdGenerate.Flag.Var(&generate.Level, "level", "Either 1, 2 or 3. i.e. 1=models; 2=models and controllers; 3=models, controllers and routers.")
CmdGenerate.Flag.Var(&generate.Fields, "fields", "List of table Fields.")
CmdGenerate.Flag.Var(&generate.DDL, "ddl", "Generate DDL Migration")

// bee generate routers
CmdGenerate.Flag.Var(&generate.ControllerDirectory, "ctrlDir",
"Controller directory. Bee scans this directory and its sub directory to generate routers")
CmdGenerate.Flag.Var(&generate.RoutersFile, "routersFile",
"Routers file. If not found, Bee create a new one. Bee will truncates this file and output routers info into this file")
CmdGenerate.Flag.Var(&generate.RouterPkg, "routersPkg",
`router's package. Default is routers, it means that "package routers" in the generated file`)

commands.AvailableCommands = append(commands.AvailableCommands, CmdGenerate)
}

Expand All @@ -97,13 +110,25 @@ func GenerateCode(cmd *commands.Command, args []string) int {
model(cmd, args, currpath)
case "view":
view(args, currpath)
case "routers":
genRouters(cmd, args)
default:
beeLogger.Log.Fatal("Command is missing")
}
beeLogger.Log.Successf("%s successfully generated!", strings.Title(gcmd))
return 0
}

func genRouters(cmd *commands.Command, args []string) {
err := cmd.Flag.Parse(args[1:])
beeLogger.Log.Infof("input parameter: %v", args)
if err != nil {
beeLogger.Log.Errorf("could not parse input parameter: %+v", err)
return
}
generate.GenRouters()
}

func scaffold(cmd *commands.Command, args []string, currpath string) {
if len(args) < 2 {
beeLogger.Log.Fatal("Wrong number of arguments. Run: bee help generate")
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/hprose/hprose.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func createhprose(cmd *commands.Command, args []string) int {
var packpath string
var err error
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
beeLogger.Log.Info("Generate api project support GOPATH")
version.ShowShortVersionBanner()
apppath, packpath, err = utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
}
} else {
beeLogger.Log.Info("generate api project support go modules.")
beeLogger.Log.Info("Generate api project support go modules.")
apppath = path.Join(utils.GetBeeWorkPath(), args[0])
packpath = args[0]
if beegoVersion.String() == `` {
Expand Down
11 changes: 7 additions & 4 deletions cmd/commands/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var CmdNew = &commands.Command{
Short: "Creates a Beego application",
Long: `
Creates a Beego application for the given app name in the current directory.
now default supoort generate a go modules project
now defaults to generating as a go modules project
The command 'new' creates a folder named [appname] [-gopath=false] [-beego=v1.12.3] and generates the following structure:
├── main.go
Expand Down Expand Up @@ -104,6 +104,9 @@ import (
"testing"
"runtime"
"path/filepath"
"github.com/beego/beego/v2/core/logs"
_ "{{.Appname}}/routers"
beego "github.com/beego/beego/v2/server/web"
Expand All @@ -123,7 +126,7 @@ func TestBeego(t *testing.T) {
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
logs.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
Expand Down Expand Up @@ -276,14 +279,14 @@ func CreateApp(cmd *commands.Command, args []string) int {
var packPath string
var err error
if gopath == `true` {
beeLogger.Log.Info("generate new project support GOPATH")
beeLogger.Log.Info("Generate new project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
}
} else {
beeLogger.Log.Info("generate new project support go modules.")
beeLogger.Log.Info("Generate new project support go modules.")
appPath = path.Join(utils.GetBeeWorkPath(), args[0])
packPath = args[0]
if beegoVersion.String() == `` {
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/run/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

var (
swaggerVersion = "3"
swaggerlink = "https://github.com/beego/swagger/archive/v" + swaggerVersion + ".zip"
swaggerVersion = "4.6.1"
swaggerlink = "https://codeload.github.com/beego/swagger/zip/refs/tags/v" + swaggerVersion
)

func downloadFromURL(url, fileName string) {
Expand Down
3 changes: 3 additions & 0 deletions cmd/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/beego/bee/v2/cmd/commands"
"github.com/beego/bee/v2/config"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
)

var CmdUpdate = &commands.Command{
Expand All @@ -34,5 +35,7 @@ func updateBee(cmd *commands.Command, args []string) int {
if err := cmdUp.Run(); err != nil {
beeLogger.Log.Warnf("Run cmd err:%s", err)
}
// update the Time when updateBee every time
utils.UpdateLastPublishedTime()
return 0
}
5 changes: 3 additions & 2 deletions cmd/commands/version/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
)

// RuntimeInfo holds information about the current runtime.
Expand All @@ -22,7 +23,7 @@ type RuntimeInfo struct {
GOROOT string
Compiler string
BeeVersion string
BeegoVersion string
Published string
}

// InitBanner loads the banner and prints it to output
Expand Down Expand Up @@ -59,7 +60,7 @@ func show(out io.Writer, content string) {
runtime.GOROOT(),
runtime.Compiler,
version,
GetBeegoVersion(),
utils.GetLastPublishedTime(),
})
if err != nil {
beeLogger.Log.Error(err.Error())
Expand Down
6 changes: 6 additions & 0 deletions generate/g.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ var Level utils.DocValue
var Tables utils.DocValue
var Fields utils.DocValue
var DDL utils.DocValue


// bee generate routers
var ControllerDirectory utils.DocValue
var RoutersFile utils.DocValue
var RouterPkg utils.DocValue
Loading

0 comments on commit a75a0c8

Please sign in to comment.