From ee489ba3bbca128951f078aff5e9e786a664d2c9 Mon Sep 17 00:00:00 2001 From: qiantao Date: Tue, 2 Jun 2020 18:19:48 +0800 Subject: [PATCH] support ldflags --- cmd/commands/run/run.go | 3 +++ cmd/commands/run/watch.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/commands/run/run.go b/cmd/commands/run/run.go index bcd6251..9eec587 100644 --- a/cmd/commands/run/run.go +++ b/cmd/commands/run/run.go @@ -46,6 +46,8 @@ var ( excludedPaths utils.StrFlags // Pass through to -tags arg of "go build" buildTags string + // Pass through to -ldflags arg of "go build" + buildLDFlags string // Application path currpath string // Application name @@ -72,6 +74,7 @@ func init() { CmdRun.Flag.Var(&excludedPaths, "e", "List of paths to exclude.") CmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Enable watch vendor folder.") CmdRun.Flag.StringVar(&buildTags, "tags", "", "Set the build tags. See: https://golang.org/pkg/go/build/") + CmdRun.Flag.StringVar(&buildLDFlags, "ldflags", "", "Set the build ldflags. See: https://golang.org/pkg/go/build/") CmdRun.Flag.StringVar(&runmode, "runmode", "", "Set the Beego run mode.") CmdRun.Flag.StringVar(&runargs, "runargs", "", "Extra args to run application") CmdRun.Flag.Var(&extraPackages, "ex", "List of extra package to watch.") diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index 39816b2..0f881ce 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -25,7 +25,7 @@ import ( "time" "github.com/beego/bee/config" - beeLogger "github.com/beego/bee/logger" + "github.com/beego/bee/logger" "github.com/beego/bee/logger/colors" "github.com/beego/bee/utils" "github.com/fsnotify/fsnotify" @@ -158,6 +158,9 @@ func AutoBuild(files []string, isgenerate bool) { if buildTags != "" { args = append(args, "-tags", buildTags) } + if buildLDFlags != "" { + args = append(args, "-ldflags", buildLDFlags) + } args = append(args, files...) bcmd := exec.Command(cmdName, args...)