go 代码生成工具 基于sqlx echo mysql
go code generater based on sqlx echo by mysql
go get github.com/guoanfamily/gcg
- create a folder in go src folder named with your projectname
mkdir projectname
cd projectname
- create a config.yaml file and edit it like this:
- Name: service
Database: mysql
Username: root
Password: ""
Host: localhost
Port: 3306
Table: "company_info,ebook"
ServicePort: 9091
3.init the project use command in your project folder
gcg init [-config=config.yaml]
4.the file struct like this
projectname
--controller
----controller.go
----gen_table.go
--model
----service
------gen_table.go
------gen_db.go
--router
----gen_table.go
----router.go
--main.go
5.run the project
go run main.go
6.additional command
if you want add table in your exist project,just run ,split tablename with ','
gcg add [-tables=tablename1,tablename2]
and then add this code in your router.go file
{{tablename}}Add(e)
//start server