GoFrame是一款模块化、高性能、企业级的Go基础开发框架。GoFrame不是一款WEB/RPC框架,而是一款通用性的基础开发框架,是Golang标准库的一个增强扩展级,包含通用核心的基础开发组件,优点是实战化、模块化、文档全面、模块丰富、易用性高、通用性强、面向团队。
如果您想使用Golang开发一个业务型项目,无论是小型还是中大型项目,GoFrame是您的不二之选。如果您想开发一个Golang组件库,GoFrame提供开箱即用、丰富强大的基础组件库也能助您的工作事半功倍。
一、goFrame CLI工具搭建
1.安装
1) 预编译的二进制文件
您还可以gf使用预构建的二进制文件安装工具:https://github.com/gogf/gf/releases
- Mac&Linux
wget -O gf https://github.com/gogf/gf/releases/latest/download/gf_$(go env GOOS)_$(go env GOARCH) && chmod +x gf && ./gf install -y && rm ./gf
如果您正在使用zsh,您可能需要通过命令重命名别名来解决和alias gf=gf之间的冲突。gf git fetch
- Windows
手动下载,执行它,然后按照说明进行操作。
- 数据库
sqlite
和命令默认oracle
不支持,因为它需要,您可以手动对源代码进行一些更改并进行构建。gf gencgogcc
2) 手动安装
git clone https://github.com/gogf/gf && cd gf/cmd/gf && go install
2.相关命令
$ gf
USAGE
gf COMMAND [OPTION]
COMMAND
env show current Golang environment variables #显示当前Go环境变量
run running go codes with hot-compiled-like feature #运行具有热编译功能的go代码
gen automatically generate go files for dao/do/entity/pb/pbentity #自动为dao/do/entity/pb/pbentity生成go文件
tpl template parsing and building commands #模板解析和构建命令
init create and initialize an empty GoFrame project #创建并初始化空的GoFrame项目
pack packing any file/directory to a resource file, or a go file #将任何文件/目录打包到资源文件或go文件
build cross-building go project for lots of platforms #跨平台构构建go项目
docker build docker image for current GoFrame project #docker为当前GoFrame项目构建docker映像
install install gf binary to system (might need root/admin permission) #将gf二进制文件安装到系统(可能需要root/admin权限)
version show version information of current binary #显示当前二进制文件的版本信息
OPTION
-y, --yes all yes for all command without prompt ask #所有是所有命令,无提示询问
-v, --version show version information of current binary #显示当前二进制文件的版本信息
-d, --debug show internal detailed debugging information #显示内部详细调试信息
-h, --help more information about this command #帮助,详情
ADDITIONAL
Use "gf COMMAND -h" for details about a command.
二、验证是否安装完成
1.查看版本
gf -v
or
gf version
☁ ~ gf -v
GoFrame CLI Tool v2.1.0-rc4, https://goframe.org
GoFrame Version: cannot find go.mod
CLI Installed At: /usr/local/bin/gf
CLI Built Detail:
Go Version: go1.17.10
GF Version: v2.1.0-rc4
Git Commit: 2022-06-01 16:36:40 0639becccc486fda179b81e7a685f67c91b173a4
Build Time: 2022-06-01 16:34:52
2.创建项目
1)使用方式
gf init 项目名称
☁ src gf init getStart
initializing...
initialization done!
you can now run "cd getStart && gf run main.go" to start your journey, enjoy!
查看该返回内容则表示项目创建完成
三、目录介绍
├── Makefile
├── README.MD
├── api # 接口定义目录
│ └── v1 # 接口的版本目录
│ └── hello.go # 路由文件
├── go.mod
├── go.sum
├── internal # 业务逻辑目录
│ ├── cmd # 命令行入口
│ │ └── cmd.go
│ ├── consts
│ │ └── consts.go
│ ├── controller
│ │ └── hello.go
│ ├── model
│ │ └── entity
│ ├── packed
│ │ └── packed.go
│ └── service
│ └── internal
│ ├── dao
│ └── do
├── main
├── main.go # 入口文件
├── manifest
│ ├── config # 业务相关配置目录
│ │ └── config.yaml
│ ├── deploy
│ │ └── kustomize # K8S部署配置
│ │ ├── base
│ │ │ ├── deployment.yaml
│ │ │ ├── kustomization.yaml
│ │ │ └── service.yaml
│ │ └── overlays
│ │ └── develop
│ │ ├── configmap.yaml
│ │ ├── deployment.yaml
│ │ └── kustomization.yaml
│ └── docker # Docker部署配置
│ ├── Dockerfile
│ └── docker.sh
├── resource
│ ├── i18n
│ ├── public
│ │ ├── html
│ │ ├── plugin
│ │ └── resource
│ │ ├── css
│ │ ├── image
│ │ └── js
│ └── template
└── utility
基本介绍就到这里啦,后面就是具体如何进行使用了,待更新。