第一步、安装
# 从 Github 上安装
go install github.com/gogf/gf/cmd/gf/v2@v2.7.2
# 从 coding 安装
go install e.coding.net/mogublog/github/gf/v2@v2.7.2
第二步、项目代码初始化
# 当前目录初始化
gf init .
# 新建目录初始化
gf init myapp
第三步、完善配置文件
# hack/config.yaml
# 代码生成配置
gfcli:
gen:
dao:
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
tables: "order,products"
# 数据库配置
database:
default:
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
user:
link: "sqlite::@file(/var/data/db.sqlite3)"
logger:
path: "/var/log/gf-app/sql"
level: "all"
stdout: true
default:
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/user_center"
debug: true
# 日志配置
logger:
path: "/var/log"
level: "all"
stdout: false
# Redis 配置
redis:
default:
address: 127.0.0.1:6379
db: 1
pass: 123456
idleTimeout: 600