beego学习———安装bee

Bee安装 有各种坑,一会儿GOPATH的问题,一会儿局部的问题了
唉,搞了一个小时

很重要的问题!!!!!!!!!!!!

beego的bee工具只能强制新建项目在GOPATH/src目录下
虽然在别的地方也可以新建,但是使用bee 其他 的命令会有一大堆报错 一定要切记

配置好环境变量

这步很重要
首先要查看自己的go path 和go root的路径

安装

首先我们进入gopath的路径下
执行命令

go get -u github.com/beego/bee/v2

可能会失败
如果报错
go go.mod file not found in current directory or any parent directory
所以这个时候我们需要设置

go env -w GO111MODULE=auto

意外情况

如果上述还是失败了
没关系,我们直接拷贝源码
首先进入我们gopath的路径
执行 进入官网 https://github.com/beego/bee

go clone git@github.com:beego/bee.git

任意选择其中之一的方式

然后执行命令

go build

然后把exe 放入到 gopath下的bin目录下:

然后执行cmd 输入 bee
安装成功!!!

运行

go mod tidy
bee run


运行成功!!

bee 命令

我们在命令行输入 bee,可以看到如下的信息:

Bee is a Fast and Flexible tool for managing your Beego Web Application.

Usage:

    bee command [arguments]

The commands are:

    version     show the bee & beego version
    migrate     run database migrations
    api         create an api application base on beego framework
    bale        packs non-Go files to Go source files    
    new         create an application base on beego framework
    run         run the app which can hot compile
    pack        compress an beego project
    fix         Fixes your application by making it compatible with newer versions of Beego
    dlv         Start a debugging session using Delve
    dockerize   Generates a Dockerfile for your Beego application
    generate    Source code generator
    hprose      Creates an RPC application based on Hprose and Beego frameworks
    pack        Compresses a Beego application into a single file
    rs          Run customized scripts
    run         Run the application by starting a local development server
    server      serving static content over HTTP on port

Use bee help [command] for more information about a command.

new 命令

bee new apiproject
new 命令是新建一个 Web 项目,我们在命令行下执行 bee new <项目名> 就可以创建一个新的项目。

api 命令

bee api apiproject

run 命令

bee run
我们在开发 Go 项目的时候最大的问题是经常需要自己手动去编译再运行,bee run 命令是监控 beego 的项目,通过 fsnotify监控文件系统。
上面的 new 命令是用来新建 Web 项目,不过很多用户使用 beego 来开发 API 应用。

pack 命令

bee pack
pack 目录用来发布应用的时候打包,会把项目打包成 zip 包,这样我们部署的时候直接把打包之后的项目上传,解压就可以部署了

bale 命令

这个命令目前仅限内部使用,具体实现方案未完善,主要用来压缩所有的静态文件变成一个变量申明文件,全部编译到二进制文件里面,用户发布的时候携带静态文件,包括 js、css、img 和 views。最后在启动运行时进行非覆盖式的自解压。

version 命令

bee version
这个命令是动态获取 bee、beego 和 Go 的版本,这样一旦用户出现错误,可以通过该命令来查看当前的版本

generate 命令

bee generate
这个命令是用来自动化的生成代码的,包含了从数据库一键生成 model,(感觉和django类似)还包含了 scaffold 的,通过这个命令,让大家开发代码快速高效

bee generate scaffold [scaffoldname] [-fields=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]
    The generate scaffold command will do a number of things for you.
    -fields: a list of table fields. Format: field:type, ...
    -driver: [mysql | postgres | sqlite], the default is mysql
    -conn:   the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test
    example: bee generate scaffold post -fields="title:string,body:text"

bee generate model [modelname] [-fields=""]
    generate RESTful model based on fields
    -fields: a list of table fields. Format: field:type, ...

bee generate controller [controllerfile]
    generate RESTful controllers

bee generate view [viewpath]
    generate CRUD view in viewpath

bee generate migration [migrationfile] [-fields=""]
    generate migration file for making database schema update
    -fields: a list of table fields. Format: field:type, ...

bee generate docs
    generate swagger doc file

bee generate test [routerfile]
    generate testcase

bee generate appcode [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-level=3]
    generate appcode based on an existing database
    -tables: a list of table names separated by ',', default is empty, indicating all tables
    -driver: [mysql | postgres | sqlite], the default is mysql
    -conn:   the connection string used by the driver.
             default for mysql:    root:@tcp(127.0.0.1:3306)/test
             default for postgres: postgres://postgres:postgres@127.0.0.1:5432/postgres
    -level:  [1 | 2 | 3], 1 = models; 2 = models,controllers; 3 = models,controllers,router

例子:

bee generate scaffold user -fields="id:int64,name:string" -driver=mysql -conn="root:admin*123"@tcp(127.0.0.1:3306)/beego_db

migrate 命令

bee migrate
这个命令是应用的数据库迁移命令,主要是用来每次应用升级,降级的SQL管理。

dockerize 命令

这个命令可以通过生成Dockerfile文件来实现docker化你的应用。

例子:
生成一个以1.6.4版本Go环境为基础镜像的Dockerfile,并暴露9000端口:

$ 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.

bee 工具配置文件

您可能已经注意到,在 bee 工具的源码目录下有一个 bee.json 文件,这个文件是针对 bee 工具的一些行为进行配置。该功能还未完全开发完成,不过其中的一些选项已经可以使用:

"version": 0:配置文件版本,用于对比是否发生不兼容的配置格式版本。
"go_install": false:如果您的包均使用完整的导入路径(例如:github.com/user/repo/subpkg),则可以启用该选项来进行 go install 操作,加快构建操作。
"watch_ext": []:用于监控其它类型的文件(默认只监控后缀为 .go 的文件)。
"dir_structure":{}:如果您的目录名与默认的 MVC 架构的不同,则可以使用该选项进行修改。
"cmd_args": []:如果您需要在每次启动时加入启动参数,则可以使用该选项。
"envs": []:如果您需要在每次启动时设置临时环境变量参数,则可以使用该选项。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值