diff --git a/.gitignore b/.gitignore index a4c4e18..ab1571f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ _obj _test .idea +.vscode # Architecture specific extensions/prefixes *.[568vq] diff --git a/.travis.yml b/.travis.yml index 933c032..2624ead 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: go go: - - 1.5.3 - - 1.4.3 - - 1.3.3 + - 1.6.3 + - 1.7.3 diff --git a/Beefile b/Beefile index 7d682df..16e5022 100644 --- a/Beefile +++ b/Beefile @@ -13,3 +13,4 @@ cmd_args: [] envs: [] database: driver: "mysql" +enable_reload: false diff --git a/README.md b/README.md index 16f6039..b264ffb 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,22 @@ go get -u github.com/beego/bee ## Basic commands -Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include: +Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include: + ``` - new Create a Beego application - run Run the app and start a Web server for development - pack Compress a beego project into a single file - api Create an API beego application - hprose Create an rpc application use hprose base on beego framework - bale Packs non-Go files to Go source files + new Creates a Beego application + run Run the application by starting a local development server + pack Compresses a Beego application into a single file + api Creates a Beego API application + hprose Creates an RPC application based on Hprose and Beego frameworks + bale Transforms non-Go files to Go source files version Prints the current Bee version generate Source code generator - migrate Run database migrations - fix Fix the Beego application to make it compatible with Beego 1.6 + migrate Runs database migrations + fix Fixes your application by making it compatible with newer versions of Beego + dockerize Generates a Dockerfile for your Beego application ``` + ### bee version To display the current version of `bee`, `beego` and `go` installed on your machine: @@ -55,18 +58,37 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 +\____/ \___| \___| v1.6.2 -├── Beego : 1.7.0 -├── GoVersion : go1.6.2 -├── GOOS : windows +├── Beego : 1.7.2 +├── GoVersion : go1.7.4 +├── GOOS : linux ├── GOARCH : amd64 -├── NumCPU : 4 -├── GOPATH : C:\Users\beeuser\go -├── GOROOT : C:\go +├── NumCPU : 2 +├── GOPATH : /home/beeuser/.go +├── GOROOT : /usr/lib/go ├── Compiler : gc -└── Date : Monday, 22 Aug 2016 -``` +└── Date : Monday, 26 Dec 2016 +``` + +You can also change the output format using `-o` flag: + +```bash +$ bee version -o json +{ + "GoVersion": "go1.7.4", + "GOOS": "linux", + "GOARCH": "amd64", + "NumCPU": 2, + "GOPATH": "/home/beeuser/.go", + "GOROOT": "/usr/lib/go", + "Compiler": "gc", + "BeeVersion": "1.6.2", + "BeegoVersion": "1.7.2" +} +``` + +For more information on the usage, run `bee help version`. ### bee new @@ -79,26 +101,26 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 14:53:45 [INFO] Creating application... - create C:\Users\beeuser\go\src\github.com\user\my-web-app\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\conf\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\controllers\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\models\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\routers\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\tests\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\static\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\static\js\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\static\css\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\static\img\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\views\ - create C:\Users\beeuser\go\src\github.com\user\my-web-app\conf\app.conf - create C:\Users\beeuser\go\src\github.com\user\my-web-app\controllers\default.go - create C:\Users\beeuser\go\src\github.com\user\my-web-app\views\index.tpl - create C:\Users\beeuser\go\src\github.com\user\my-web-app\routers\router.go - create C:\Users\beeuser\go\src\github.com\user\my-web-app\tests\default_test.go - create C:\Users\beeuser\go\src\github.com\user\my-web-app\main.go -2016/08/22 14:53:45 [SUCC] New application successfully created! +\____/ \___| \___| v1.6.2 +2016/12/26 22:28:11 INFO ▶ 0001 Creating application... + create /home/beeuser/.go/src/github.com/user/my-web-app/ + create /home/beeuser/.go/src/github.com/user/my-web-app/conf/ + create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/ + create /home/beeuser/.go/src/github.com/user/my-web-app/models/ + create /home/beeuser/.go/src/github.com/user/my-web-app/routers/ + create /home/beeuser/.go/src/github.com/user/my-web-app/tests/ + create /home/beeuser/.go/src/github.com/user/my-web-app/static/ + create /home/beeuser/.go/src/github.com/user/my-web-app/static/js/ + create /home/beeuser/.go/src/github.com/user/my-web-app/static/css/ + create /home/beeuser/.go/src/github.com/user/my-web-app/static/img/ + create /home/beeuser/.go/src/github.com/user/my-web-app/views/ + create /home/beeuser/.go/src/github.com/user/my-web-app/conf/app.conf + create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/default.go + create /home/beeuser/.go/src/github.com/user/my-web-app/views/index.tpl + create /home/beeuser/.go/src/github.com/user/my-web-app/routers/router.go + create /home/beeuser/.go/src/github.com/user/my-web-app/tests/default_test.go + create /home/beeuser/.go/src/github.com/user/my-web-app/main.go +2016/12/26 22:28:11 SUCCESS ▶ 0002 New application successfully created! ``` For more information on the usage, run `bee help new`. @@ -130,14 +152,15 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 15:11:01 Packaging application: C:\Users\beeuser\go\src\github.com\user\my-web-app -2016/08/22 15:11:01 Building application... -2016/08/22 15:11:01 Env: GOOS=windows GOARCH=amd64 -2016/08/22 15:11:08 Build successful -2016/08/22 15:11:08 Excluding relpath prefix: . -2016/08/22 15:11:08 Excluding relpath suffix: .go:.DS_Store:.tmp -2016/08/22 15:11:10 Writing to output: `C:\Users\beeuser\go\src\github.com\user\my-web-app\my-web-app.tar.gz` +\____/ \___| \___| v1.6.2 +2016/12/26 22:29:29 INFO ▶ 0001 Packaging application on '/home/beeuser/.go/src/github.com/user/my-web-app'... +2016/12/26 22:29:29 INFO ▶ 0002 Building application... +2016/12/26 22:29:29 INFO ▶ 0003 Using: GOOS=linux GOARCH=amd64 +2016/12/26 22:29:31 SUCCESS ▶ 0004 Build Successful! +2016/12/26 22:29:31 INFO ▶ 0005 Writing to output: /home/beeuser/.go/src/github.com/user/my-web-app/my-web-app.tar.gz +2016/12/26 22:29:31 INFO ▶ 0006 Excluding relpath prefix: . +2016/12/26 22:29:31 INFO ▶ 0007 Excluding relpath suffix: .go:.DS_Store:.tmp +2016/12/26 22:29:32 SUCCESS ▶ 0008 Application packed! ``` For more information on the usage, run `bee help pack`. @@ -153,23 +176,23 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 15:14:10 [INFO] Creating API... - create C:\Users\beeuser\go\src\github.com\user\my-api - create C:\Users\beeuser\go\src\github.com\user\my-api\conf - create C:\Users\beeuser\go\src\github.com\user\my-api\controllers - create C:\Users\beeuser\go\src\github.com\user\my-api\tests - create C:\Users\beeuser\go\src\github.com\user\my-api\conf\app.conf - create C:\Users\beeuser\go\src\github.com\user\my-api\models - create C:\Users\beeuser\go\src\github.com\user\my-api\routers\ - create C:\Users\beeuser\go\src\github.com\user\my-api\controllers\object.go - create C:\Users\beeuser\go\src\github.com\user\my-api\controllers\user.go - create C:\Users\beeuser\go\src\github.com\user\my-api\tests\default_test.go - create C:\Users\beeuser\go\src\github.com\user\my-api\routers\router.go - create C:\Users\beeuser\go\src\github.com\user\my-api\models\object.go - create C:\Users\beeuser\go\src\github.com\user\my-api\models\user.go - create C:\Users\beeuser\go\src\github.com\user\my-api\main.go -2016/08/22 15:14:10 [SUCC] New API successfully created! +\____/ \___| \___| v1.6.2 +2016/12/26 22:30:12 INFO ▶ 0001 Creating API... + create /home/beeuser/.go/src/github.com/user/my-api + create /home/beeuser/.go/src/github.com/user/my-api/conf + create /home/beeuser/.go/src/github.com/user/my-api/controllers + create /home/beeuser/.go/src/github.com/user/my-api/tests + create /home/beeuser/.go/src/github.com/user/my-api/conf/app.conf + create /home/beeuser/.go/src/github.com/user/my-api/models + create /home/beeuser/.go/src/github.com/user/my-api/routers/ + create /home/beeuser/.go/src/github.com/user/my-api/controllers/object.go + create /home/beeuser/.go/src/github.com/user/my-api/controllers/user.go + create /home/beeuser/.go/src/github.com/user/my-api/tests/default_test.go + create /home/beeuser/.go/src/github.com/user/my-api/routers/router.go + create /home/beeuser/.go/src/github.com/user/my-api/models/object.go + create /home/beeuser/.go/src/github.com/user/my-api/models/user.go + create /home/beeuser/.go/src/github.com/user/my-api/main.go +2016/12/26 22:30:12 SUCCESS ▶ 0002 New API successfully created! ``` For more information on the usage, run `bee help api`. @@ -185,16 +208,26 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 16:09:13 [INFO] Creating Hprose application... - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\conf - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\conf\app.conf - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\models - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\models\object.go - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\models\user.go - create C:\Users\beeuser\go\src\github.com\user\my-rpc-app\main.go -2016/08/22 16:09:13 [SUCC] New Hprose application successfully created! +\____/ \___| \___| v1.6.2 +2016/12/26 22:30:58 INFO ▶ 0001 Creating application... + create /home/beeuser/.go/src/github.com/user/my-rpc-app/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/models/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/js/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/css/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/img/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/ + create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/app.conf + create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/default.go + create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/index.tpl + create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/router.go + create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/default_test.go + create /home/beeuser/.go/src/github.com/user/my-rpc-app/main.go +2016/12/26 22:30:58 SUCCESS ▶ 0002 New application successfully created! ``` For more information on the usage, run `bee help hprose`. @@ -210,11 +243,9 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 16:37:24 [INFO] Detected bee.json -2016/08/22 16:37:24 [INFO] Packaging directory(static/js) -2016/08/22 16:37:24 [INFO] Packaging directory(static/css) -2016/08/22 16:37:24 [SUCC] Baled resources successfully! +\____/ \___| \___| v1.6.2 +2016/12/26 22:32:41 INFO ▶ 0001 Loading configuration from 'bee.json'... +2016/12/26 22:32:41 SUCCESS ▶ 0002 Baled resources successfully! ``` For more information on the usage, run `bee help bale`. @@ -238,15 +269,35 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.5.0 -2016/08/22 16:55:30 [INFO] Using 'Hello' as controller name -2016/08/22 16:55:30 [INFO] Using 'controllers' as package name - create C:\Users\beeuser\go\src\github.com\user\my-web-app/controllers/hello.go -2016/08/22 16:55:30 [SUCC] Controller successfully generated! +\____/ \___| \___| v1.6.2 +2016/12/26 22:33:58 INFO ▶ 0001 Using 'Hello' as controller name +2016/12/26 22:33:58 INFO ▶ 0002 Using 'controllers' as package name + create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/hello.go +2016/12/26 22:33:58 SUCCESS ▶ 0003 Controller successfully generated! ``` For more information on the usage, run `bee help generate`. +### bee dockerize + +Bee also helps you dockerize your Beego application by generating a Dockerfile. + +For example, to generate a Dockerfile with `Go version 1.6.4` and exposing port `9000`: + +```bash +$ bee dockerize -image="library/golang:1.6.4" -expose=9000 +______ +| ___ \ +| |_/ / ___ ___ +| ___ \ / _ \ / _ \ +| |_/ /| __/| __/ +\____/ \___| \___| v1.6.2 +2016/12/26 22:34:54 INFO ▶ 0001 Generating Dockerfile... +2016/12/26 22:34:54 SUCCESS ▶ 0002 Dockerfile generated. +``` + +For more information on the usage, run `bee help dockerize`. + ## Shortcuts Because you'll likely type these generator commands over and over, it makes sense to create aliases: @@ -270,10 +321,33 @@ For instance, to get more information about the `run` command: ```bash $ bee help run -usage: bee run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-tags=goBuildTags] +USAGE + bee run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE] -Run command will supervise the file system of the beego project using inotify, -it will recompile and restart the app after any modifications. +OPTIONS + -downdoc + Enable auto-download of the swagger file if it does not exist. + + -e=[] + List of paths to exclude. + + -gendoc + Enable auto-generate the docs. + + -main=[] + Specify main go files. + + -runmode + Set the Beego run mode. + + -tags + Set the build tags. See: https://golang.org/pkg/go/build/ + + -vendor=false + Enable watch vendor folder. + +DESCRIPTION + Run command will supervise the filesystem of the application for any changes, and recompile/restart it. ``` ## Contributing @@ -333,14 +407,14 @@ A feature should be made of commits splitted by **logical chunks** (no half-done how many commits your changes require. - Write insightful and descriptive commit messages. It lets us and future contributors quickly understand your changes -without having to read your changes. Please provide a summary in the first line (50-72 characters) and eventually, +without having to read your changes. Please provide a summary in the first line (50-72 characters) and eventually, go to greater lengths in your message's body. A good example can be found in [Angular commit message format](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format). - Please **include the appropriate test cases** for your patch. - Make sure all tests pass before submitting your changes. -- Rebase your commits. It may be that new commits have been introduced on `develop`. +- Rebase your commits. It may be that new commits have been introduced on `develop`. Rebasing will update your branch with the most recent code and make your changes easier to review: ``` @@ -391,4 +465,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -``` \ No newline at end of file +``` diff --git a/banner.go b/banner.go index b9a4789..fb06316 100644 --- a/banner.go +++ b/banner.go @@ -8,7 +8,8 @@ import ( "text/template" ) -type vars struct { +// RuntimeInfo holds information about the current runtime. +type RuntimeInfo struct { GoVersion string GOOS string GOARCH string @@ -45,7 +46,7 @@ func show(out io.Writer, content string) { logger.Fatalf("Cannot parse the banner template: %s", err) } - err = t.Execute(out, vars{ + err = t.Execute(out, RuntimeInfo{ getGoVersion(), runtime.GOOS, runtime.GOARCH, diff --git a/bee.go b/bee.go index ca1e25e..690bc07 100644 --- a/bee.go +++ b/bee.go @@ -25,7 +25,7 @@ import ( "text/template" ) -const version = "1.6.2" +const version = "1.8.0" // Command is the unit of execution type Command struct { @@ -99,12 +99,7 @@ func (c *Command) Options() map[string]string { c.Flag.VisitAll(func(f *flag.Flag) { defaultVal := f.DefValue if len(defaultVal) > 0 { - if strings.Contains(defaultVal, ":") { - // Truncate the flag's default value by appending '...' at the end - options[f.Name+"="+strings.Split(defaultVal, ":")[0]+":..."] = f.Usage - } else { - options[f.Name+"="+defaultVal] = f.Usage - } + options[f.Name+"="+defaultVal] = f.Usage } else { options[f.Name] = f.Usage } @@ -126,6 +121,7 @@ var availableCommands = []*Command{ //cmdRundocs, cmdMigrate, cmdFix, + cmdDockerize, } var logger = GetBeeLogger(os.Stdout) @@ -209,7 +205,9 @@ Use {{"bee help [topic]" | bold}} for more information about that topic. var helpTemplate = `{{"USAGE" | headline}} {{.UsageLine | printf "bee %s" | bold}} {{if .Options}}{{endline}}{{"OPTIONS" | headline}}{{range $k,$v := .Options}} - {{$k | printf "-%-12s" | bold}} {{$v}}{{end}}{{endline}}{{end}} + {{$k | printf "-%s" | bold}} + {{$v}} + {{end}}{{end}} {{"DESCRIPTION" | headline}} {{tmpltostr .Long . | trim}} ` diff --git a/bee.json b/bee.json index 1bd099f..e1bf758 100644 --- a/bee.json +++ b/bee.json @@ -16,5 +16,6 @@ "envs": [], "database": { "driver": "mysql" - } + }, + "enable_reload": false } \ No newline at end of file diff --git a/conf.go b/conf.go index bca17f9..e352f84 100644 --- a/conf.go +++ b/conf.go @@ -45,7 +45,8 @@ var defaultConf = `{ "envs": [], "database": { "driver": "mysql" - } + }, + "enable_reload": false } ` var conf struct { @@ -75,6 +76,7 @@ var conf struct { Driver string Conn string } + EnableReload bool `json:"enable_reload" yaml:"enable_reload"` } // loadConfig loads customized configuration. @@ -90,7 +92,7 @@ func loadConfig() (err error) { if fileInfo.Name() == "bee.json" { logger.Info("Loading configuration from 'bee.json'...") - err = parseJSON(path, conf) + err = parseJSON(path, &conf) if err != nil { logger.Errorf("Failed to parse JSON file: %s", err) return err @@ -100,7 +102,7 @@ func loadConfig() (err error) { if fileInfo.Name() == "Beefile" { logger.Info("Loading configuration from 'Beefile'...") - err = parseYAML(path, conf) + err = parseYAML(path, &conf) if err != nil { logger.Errorf("Failed to parse YAML file: %s", err) return err @@ -151,7 +153,7 @@ func parseJSON(path string, v interface{}) error { if err != nil { return err } - err = json.Unmarshal(data, &v) + err = json.Unmarshal(data, v) if err != nil { return err } @@ -167,7 +169,7 @@ func parseYAML(path string, v interface{}) error { if err != nil { return err } - err = yaml.Unmarshal(data, &v) + err = yaml.Unmarshal(data, v) if err != nil { return err } diff --git a/dockerize.go b/dockerize.go new file mode 100644 index 0000000..827fc8e --- /dev/null +++ b/dockerize.go @@ -0,0 +1,126 @@ +// Copyright 2016 bee authors +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package main + +import ( + "flag" + "os" + "path" + "path/filepath" + "strings" + "text/template" +) + +var cmdDockerize = &Command{ + CustomFlags: true, + UsageLine: "dockerize", + Short: "Generates a Dockerfile for your Beego application", + Long: `Dockerize generates a Dockerfile for your Beego Web Application. + The Dockerfile will compile, get the dependencies with {{"godep"|bold}}, and set the entrypoint. + + {{"Example:"|bold}} + $ bee dockerize -expose="3000,80,25" + `, + PreRun: func(cmd *Command, args []string) { ShowShortVersionBanner() }, + Run: dockerizeApp, +} + +const dockerBuildTemplate = `FROM {{.BaseImage}} + +# Godep for vendoring +RUN go get github.com/tools/godep + +# Recompile the standard library without CGO +RUN CGO_ENABLED=0 go install -a std + +ENV APP_DIR $GOPATH{{.Appdir}} +RUN mkdir -p $APP_DIR + +# Set the entrypoint +ENTRYPOINT $APP_DIR/{{.Entrypoint}} +ADD . $APP_DIR + +# Compile the binary and statically link +RUN cd $APP_DIR +RUN CGO_ENABLED=0 godep go build -ldflags '-d -w -s' + +EXPOSE {{.Expose}} +` + +// Dockerfile holds the information about the Docker container. +type Dockerfile struct { + BaseImage string + Appdir string + Entrypoint string + Expose string +} + +var ( + expose string + baseImage string +) + +func init() { + fs := flag.NewFlagSet("dockerize", flag.ContinueOnError) + fs.StringVar(&baseImage, "image", "library/golang", "Set the base image of the Docker container.") + fs.StringVar(&expose, "expose", "8080", "Port(s) to expose in the Docker container.") + cmdDockerize.Flag = *fs +} + +func dockerizeApp(cmd *Command, args []string) int { + if err := cmd.Flag.Parse(args); err != nil { + logger.Fatalf("Error parsing flags: %v", err.Error()) + } + + logger.Info("Generating Dockerfile...") + + gopath := os.Getenv("GOPATH") + dir, err := filepath.Abs(".") + MustCheck(err) + + appdir := strings.Replace(dir, gopath, "", 1) + + // 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) + } + + _, entrypoint := path.Split(appdir) + dockerfile := Dockerfile{ + BaseImage: baseImage, + Appdir: appdir, + Entrypoint: entrypoint, + Expose: expose, + } + + generateDockerfile(dockerfile) + return 0 +} + +func generateDockerfile(df Dockerfile) { + t := template.Must(template.New("dockerBuildTemplate").Parse(dockerBuildTemplate)).Funcs(BeeFuncMap()) + + f, err := os.Create("Dockerfile") + if err != nil { + logger.Fatalf("Error writing Dockerfile: %v", err.Error()) + } + defer CloseFile(f) + + t.Execute(f, df) + + logger.Success("Dockerfile generated.") +} diff --git a/g_controllers.go b/g_controllers.go index 5220210..a85f3df 100644 --- a/g_controllers.go +++ b/g_controllers.go @@ -165,7 +165,7 @@ import ( "github.com/astaxie/beego" ) -// {{controllerName}}Controller oprations for {{controllerName}} +// {{controllerName}}Controller operations for {{controllerName}} type {{controllerName}}Controller struct { beego.Controller } diff --git a/g_docs.go b/g_docs.go index fbc22b3..23e3ed5 100644 --- a/g_docs.go +++ b/g_docs.go @@ -26,6 +26,7 @@ import ( "path/filepath" "reflect" "regexp" + "runtime" "strconv" "strings" "unicode" @@ -53,25 +54,31 @@ var astPkgs map[string]*ast.Package // refer to builtin.go var basicTypes = map[string]string{ - "bool": "boolean:", - "uint": "integer:int32", - "uint8": "integer:int32", - "uint16": "integer:int32", - "uint32": "integer:int32", - "uint64": "integer:int64", - "int": "integer:int64", - "int8": "integer:int32", - "int16:int32": "integer:int32", - "int32": "integer:int32", - "int64": "integer:int64", - "uintptr": "integer:int64", - "float32": "number:float", - "float64": "number:double", - "string": "string:", - "complex64": "number:float", - "complex128": "number:double", - "byte": "string:byte", - "rune": "string:byte", + "bool": "boolean:", + "uint": "integer:int32", + "uint8": "integer:int32", + "uint16": "integer:int32", + "uint32": "integer:int32", + "uint64": "integer:int64", + "int": "integer:int64", + "int8": "integer:int32", + "int16": "integer:int32", + "int32": "integer:int32", + "int64": "integer:int64", + "uintptr": "integer:int64", + "float32": "number:float", + "float64": "number:double", + "string": "string:", + "complex64": "number:float", + "complex128": "number:double", + "byte": "string:byte", + "rune": "string:byte", + // builtin golang objects + "time.Time": "string:string", +} + +var stdlibObject = map[string]string{ + "&{time Time}": "time.Time", } func init() { @@ -402,6 +409,9 @@ func analyseControllerPkg(localName, pkgpath string) { func isSystemPackage(pkgpath string) bool { goroot := os.Getenv("GOROOT") + if goroot == "" { + goroot = runtime.GOROOT() + } if goroot == "" { logger.Fatalf("GOROOT environment variable is not set or empty") } @@ -872,10 +882,14 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { } return false, val, "object" } - if k, ok := basicTypes[fmt.Sprint(f.Type)]; ok { - return false, fmt.Sprint(f.Type), k + basicType := fmt.Sprint(f.Type) + if object, isStdLibObject := stdlibObject[basicType]; isStdLibObject { + basicType = object } - return false, fmt.Sprint(f.Type), "object" + if k, ok := basicTypes[basicType]; ok { + return false, basicType, k + } + return false, basicType, "object" } func isBasicType(Type string) bool { diff --git a/hproseapp.go b/hproseapp.go index edd01b1..50ba2bd 100644 --- a/hproseapp.go +++ b/hproseapp.go @@ -300,6 +300,10 @@ func init() { func createhprose(cmd *Command, args []string) int { output := cmd.Out() + if len(args) != 1 { + logger.Fatal("Argument [appname] is missing") + } + curpath, _ := os.Getwd() if len(args) > 1 { cmd.Flag.Parse(args[1:]) diff --git a/new.go b/new.go index eb3ab60..6eb9e73 100644 --- a/new.go +++ b/new.go @@ -87,6 +87,7 @@ func createApp(cmd *Command, args []string) int { os.Mkdir(path.Join(apppath, "static"), 0755) fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static")+string(path.Separator), "\x1b[0m") os.Mkdir(path.Join(apppath, "static", "js"), 0755) + WriteToFile(path.Join(apppath, "static", "js", "reload.min.js"), reloadJsClient) fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static", "js")+string(path.Separator), "\x1b[0m") os.Mkdir(path.Join(apppath, "static", "css"), 0755) fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static", "css")+string(path.Separator), "\x1b[0m") @@ -294,6 +295,11 @@ var indextpl = `
+ +