gogf / gf-cli Goto Github PK
View Code? Open in Web Editor NEWGoFrame Command Line Interface, which is your helpmate for building GoFrame application with convenience.
Home Page: https://goframe.org
License: MIT License
GoFrame Command Line Interface, which is your helpmate for building GoFrame application with convenience.
Home Page: https://goframe.org
License: MIT License
gf run main.go --swagger -mod=vendor
2020-02-16 19:24:33.577 build: main.go
2020-02-16 19:24:33.640 producing swagger files...
2020-02-16 19:24:33.779 Incorrect Usage: flag provided but not defined: -o
NAME:
swag init - Create docs.go
USAGE:
swag init [command options] [arguments...]
OPTIONS:
--generalInfo value Go file path in which 'swagger general API Info' is written (default: "main.go")
--dir value Directory you want to parse (default: "./")
--propertyStrategy value Property Naming Strategy like snakecase,camelcase,pascalcase (default: "camelcase") --output value Output directory for all the generated files(swagger.json, swagger.yaml and doc.go) (default: "./docs")
--parseVendor Parse go files in 'vendor' folder, disabled by default (default: false)
--parseDependency Parse go files in outside dependency folder, disabled by default (default: false)
--markdownFiles value Parse folder containing markdown files to use as description, disabled by default
--generatedTime Generate timestamp at the top of docs.go, true by default (default: false)
--help, -h show help (default: false)
2020/02/16 19:24:33 flag provided but not defined: -o
GF-CLI 生成 MSSQL的表模型有个小BUG,生成的字段名称是先strings.ToLower之后再gstr.CamelCase的,造成MSSQL生成的*_entity.go文件结构体字段名称不友好,如数据表中字段为MailID,生成的值就为Mailid,我找了一下发现是database/gdb/gdb_driver_mssql.go这个文件的222行处,做的转小写操作,这里需要修改一下。
1、设置忽略表的前缀,列如习惯表开头用“t_”, 如t_user, t_file;
习惯函数开头用"f_", 存储过程开头“pr_”
但生成model需要忽略掉前缀
2、生成model希望能把表字段注释和表注释带过来,方便阅读代码
thanks,John
My table name is "weixin_weixin_config", when i use gf gen dao -r weixin_
to generate the dao , i'cant find the weixin_config dao or model。
【建议】gf init gf-test时生成工程目录gf-test,当前gf init生成目录名一致的工程,有工程名参数时,新建目录,然后生成gf init
如题。在传了表名和模型名的时候,自动忽略生成全部表的效果,例如gf -t tableName -m modelName 生成的是对应数据库表tableName,文件名为modelName.go的模型文件。
最好有强制覆盖的选项,例如-f。
全部生成再copy或者move到实际项目目录中修改其实也不复杂,就是相对不方便。
作者大大您好,我是一位PHP开发者主要使用thinkphp,目前转向go语言使用gf框架开发
自我感觉,gf框架对PHP开发者非常友好,通俗易懂。
目前遇到有一个需求,才疏学浅难以实现,希望作者大大不吝赐教
需求:根据不同的域名前缀访问不同的模块
详情:在域名泛解析的前提下
目前根据文档提供的域名路由实现了前面三个域名与对应的路由绑定
最后一个无法实现
谢谢作者大大,作者大大辛苦了
根据effective go
packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.
能够支持在生成model时,将package名称里的下划线去掉的配置。
type Entity struct {
Id int `orm:"id,primary" json:"id"` // 主键
UserName string `orm:"user_name" json:"user_name"` // 用户名
Password string `orm:"password" json:"password"` // 密码
CreatedAt int `orm:"created_at" json:"created_at"` // 创建时间
UpdatedAt int `orm:"updated_at" json:"updated_at"` // 更新时间
Mobile string `orm:"mobile" json:"mobile"` // 手机号
LoginAt int `orm:"login_at" json:"login_at"` // 最后登录时间
LoginType int `orm:"login_type" json:"login_type"` // 登录方式
}
上面的代码中,我的id是bigint unsigned,应该生成uint64这个类型的吧?
梳理代码发现是gen_model.go这个文件中的问题
func generateStructField(field *gdb.TableField) []string {
var typeName, ormTag, jsonTag, comment string
t, _ := gregex.ReplaceString(`\(.+\)`, "", field.Type)
t = strings.ToLower(t)
switch t {
case "binary", "varbinary", "blob", "tinyblob", "mediumblob", "longblob":
typeName = "[]byte"
这里的有问题,输出t的值是bigint unsigned这种,不是bigint,需要分割一下
命令行
gf gen model ./app/model/xcx -p xcx_ -g xcx -t xcx_cat -l "mysql:root:!@#toor1025@tcp(101.132.141.31:3306)/csxcx"
config.toml 配置信息
# 数据库连接
[database]
[[database.default]]
link = "mysql:root:!@#toor1025@tcp(101.132.141.31:3306)/ytkhelp"
[[database.xcx]]
link = "mysql:root:!@#toor1025@tcp(101.132.141.31:3306)/csxcx" #测试
GoFrame CLI Tool v1.14.5, https://goframe.org
Install Path: /usr/local/bin/gf
Build Detail:
Go Version: go1.15.5
GF Version: v1.14.5
Git Commit: e5b914d
Build Time: 2020-12-14 23:06:09
[compiler]
name = "main"
version = "1.0.0"
arch = "amd64"
system = "linux"
output = ""
path = "./bin"
extra = "-ldflags \"-s -w\""
gf build main.go --pack
2020-12-19 02:40:28.339 gf pack config,public packed/data.go
path 'packed/data.go' is not empty, files might be overwrote, continue? [y/n]: y
2020-12-19 02:40:30.788 done!
2020-12-19 02:40:30.804 start building...
2020-12-19 02:40:30.804 go build -o main main.go
2020-12-19 02:40:34.819 done!
gf gen model -t merchant
2020-08-31 16:22:59.041 [DEBU] [ 13 ms] SELECT c.name as FIELD, CASE t.name WHEN 'numeric' THEN t.name + '(' + convert(varchar(20),c.xprec) + ',' + convert(varchar(20),c.xscale) + ')' WHEN 'char' THEN t.name + '(' + convert(varchar(20),c.length)+ ')' WHEN 'varchar' THEN t.name + '(' + convert(varchar(20),c.length)+ ')' ELSE t.name + '(' + convert(varchar(20),c.length)+ ')' END as TYPE FROM systypes t,syscolumns c WHERE t.xtype=c.xtype AND c.id = (SELECT id FROM sysobjects WHERE name='MERCHANT') ORDER BY c.colid
panic: runtime error: index out of range [12] with length 11
goroutine 1 [running]:
github.com/gogf/gf-cli/commands/gen.generateStructDefinition(0xc0002bbdd0, 0x8, 0x1)
/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf-cli/commands/gen/gen_model.go:186 +0x427
github.com/gogf/gf-cli/commands/gen.generateModelContentFile(0xdd8000, 0xc000338090, 0xc00001e0d0, 0x8,
0xc00001e0d0, 0x8, 0xbb1c48, 0xb, 0xbad546, 0x7)
/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf-cli/commands/gen/gen_model.go:107 +0xf0
github.com/gogf/gf-cli/commands/gen.doGenModel(0xc00004c180)
/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf-cli/commands/gen/gen_model.go:88 +0x54a
github.com/gogf/gf-cli/commands/gen.Run()
/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf-cli/commands/gen/gen.go:62 +0x34b
main.main()
/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf-cli/main.go:90 +0x50b
gf run main.go 只能热编译 main.go 文件的修改,修改main.go 导入的包文件 如何才能热编译呢?
目前gf init应该是在线拉取包的形式生成项目代码框架的。
我们目前的研发环境网络受限,目前仅能访问goproxy.io
在这样的环境下测试了最新版的gf拉取包时报Error: get the project zip md5 failed.
郭大神,这个cli工具好用,希望增加一个upx压缩选项,例如,配置了upx.exe的路径时,自动调用upx压缩
问题:
无外网情况下,使用了vendor管理依赖包。
建议:
gf run 编译时,添加mod=vendor参数,支持根据vendor目录编译。
2020-04-02 09:13:19.246 build: .\main.go
2020-04-02 09:13:19.246 rename /tmp\gf-cli\main.exe /tmp\gf-cli\main.exe~: Access is denied.
2020-04-02 09:13:19.246 go build -o /tmp\gf-cli\main.exe .\main.go
2020-04-02 09:13:20.807 build error:
go build command-line-arguments: open /tmp\gf-cli\main.exe: The process cannot access the file because it is being used by another process.
两个项目都运行 gf run main.go
, 然后修改其中一个项目. 测试环境在windows下
版本
GoFrame CLI Tool v0.7.1, https://goframe.org
Build Detail:
Go Version: go1.14
GF Version: v1.12.1
Git Commit: 76483c62719736c36992edb7e4cea92c01ca6fc5
Build Time: 2020-04-01 21:46:21
/tmp\gf-cli\main.exe
临时的可执行文件路径, 可能要修改一下. 比如在路径中加入 gf-app 这个项目相关的文本
SELECT NAME,XTYPE FROM systypes
WHERE NAME IN ('nvarchar', 'sysname')
ORDER BY XTYPE
以上sql查询,可以看到
两者 XTYPE 都是231
这就导致
github.com\gogf\[email protected]\database\gdb\gdb_driver_mssql.go
这里的语句
SELECT c.name as FIELD, CASE t.name
WHEN 'numeric' THEN t.name + '(' + convert(varchar(20),c.xprec) + ',' + convert(varchar(20),c.xscale) + ')'
WHEN 'char' THEN t.name + '(' + convert(varchar(20),c.length)+ ')'
WHEN 'varchar' THEN t.name + '(' + convert(varchar(20),c.length)+ ')'
ELSE t.name + '(' + convert(varchar(20),c.length)+ ')' END as TYPE
FROM systypes t,syscolumns c WHERE t.xtype=c.xtype -- 一个字段名可能对应多个类型
AND c.id = (SELECT id FROM sysobjects WHERE name='表名')
ORDER BY c.colid
然后后面就会出现index错位的问题
测试数据库:
sql2017
sql2008
使用 gf build 如果需要cgo支持就无法编译.
my command is gf run main.go server
2020-06-28 11:41:03.356 build: main.go
2020-06-28 11:41:03.356 go build -o /tmp/gf-cli/main server main.go
2020-06-28 11:41:03.370 build error:
can't load package: named files must be .go files: server
exit status 1
it's ok with go run.
是不是要在 gen/gen-model.go 中移除 _ "github.com/mattn/go-sqlite3" 的注释?
个人建议优先查找goroot,然后放到$goroot\bin目录下面
空白项目压缩包: https://gfcdn.johng.cn/cli/project/zip?0bdd5ca77c1ee30847d18b1e1bdb3642
解压后: boot/boot.go 文件末尾存在多余空白行
go build的时候出错!!
sunmoondeMacBook-Pro:gf-cli sunmoon$ go build
# github.com/gogf/gf-cli/commands/gen
commands/gen/gen_model.go:263:37: field.Comment undefined (type *gdb.TableField has no field or method Comment)
重新clone了一份
sunmoondeMacBook-Pro:gf-cli sunmoon$ go build
go: finding github.com/gogf/gf/os latest
go: finding github.com/gogf/gf/os/gbuild latest
build github.com/gogf/gf-cli: cannot load github.com/gogf/gf/os/gbuild: module github.com/gogf/gf@latest found (v1.10.0), but does not contain package github.com/gogf/gf/os/gbuild
sunmoondeMacBook-Pro:gf-cli sunmoon$
win10系统
>gf -v
GoFrame CLI Tool v0.7.1, https://goframe.org
Install Path: D:\develop\go\bin\gf.exe
Build Detail:
Go Version: go1.14
GF Version: v1.11.7
Git Commit: 6bccf7ca382b885f333d14b119829ac4a2fd6a4b
Build Time: 2020-03-26 15:33:53
启动后热编译
2020-03-29 23:10:42.663 [FATA] 2132: net.Listen error: listen tcp :8080: bind: Only one usage of each socket address (protocol/network address/port) is normally
permitted.
用80和8080端口均一样
我是macos系统,我按照 gf install 之后,gf 被安装到了/usr/local/bin/gf,我直接使用/usr/local/bin/gf命令正常,但是直接输入gf 命令的时候报错:
fatal: not a git repository (or any of the parent directories): .git
如题,生成 model 时,没法加前缀。
我这一个工程可能涉及到多个数据库,现在时生成之后再去修改每个包的前缀。
这种方式会造成没法直接更新 _model.go,比如最近的 ctx 方法。
有计划支持该功能吗?
renxuedong@yq ~ wget https://goframe.org/cli/linux_amd64/gf && chmod +x gf && ./gf install
--2020-08-19 19:00:12-- https://goframe.org/cli/linux_amd64/gf
正在解析主机 goframe.org (goframe.org)... 47.244.3.49
正在连接 goframe.org (goframe.org)|47.244.3.49|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://gfcdn.johng.cn/cli/linux_amd64/gf?534618d654b6f921ff166a0ccdc2f94f [跟随至新的 URL]
--2020-08-19 19:00:14-- https://gfcdn.johng.cn/cli/linux_amd64/gf?534618d654b6f921ff166a0ccdc2f94f
正在解析主机 gfcdn.johng.cn (gfcdn.johng.cn)... 36.99.196.217
正在连接 gfcdn.johng.cn (gfcdn.johng.cn)|36.99.196.217|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:21877703 (21M) [application/octet-stream]
正在保存至: “gf”
gf 100%[=====================================================================================================>] 20.86M 1.37MB/s 用时 16s
2020-08-19 19:00:31 (1.31 MB/s) - 已保存 “gf” [21877703/21877703])
zsh: exec format error: ./gf
最新版的cli工具在gf gen model 生成模型后部分方法参数接收个数和参数类型错误
gf信息
GoFrame CLI Tool v1.15.0, https://goframe.org
Install Path: /usr/local/bin/gf
Build Detail:
Go Version: go1.15.5
GF Version: v1.14.6
Git Commit: be4a975
Build Time: 2021-01-04 00:01:21
错误文件:_entity.go 62行 Update() 方法
错误文件:_model.go 101 行 Fields() 方法
还有一些无关紧要的问题
1.更新了cli后,model目录下存在原来生成的文件,不会询问是否覆盖了
辛苦作者大大了
配置文件中已经设置好表前缀参数(prefix = “app_”),但执行 gf gen model 命令时,生成的文件依旧带有表前缀(如"app\model\app_users\app_users_entity.go"),需要执行 gf gen model -p "app_" 生成出来的文件才会去掉表前缀。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.