gf README

项目的 README,来自 github.com/gogf/gf。合并为一个 markdown 文件:README.md。

English | 简体中文

goframe logo

Go Reference GoFrame CI Code Coverage Production Ready License Ask DeepWiki

Release GitHub pull requests GitHub closed pull requests GitHub issues GitHub closed issues Stars Forks

GoFrame is a powerful framework for faster, easier, and more efficient project development. Use it as a full application framework, or pick individual components as needed.

Installation

GoFrame requires Go 1.25 or later.

In an existing module, add the framework:

go get -v github.com/gogf/gf/v2@latest

Install the gf CLI:

go install github.com/gogf/gf/cmd/gf/v2@latest

Documentation

Usage

Create main.go:

package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

func main() {
	s := g.Server()
	s.BindHandler("/", func(r *ghttp.Request) {
		r.Response.Write("Hello World!")
	})
	s.SetPort(8000)
	s.Run()
}

Run it:

go mod init hello
go mod tidy
go run main.go

Open http://127.0.0.1:8000.

To scaffold a project with the gf CLI:

gf init hello
cd hello && gf run main.go

Feature Map

GoFrame is a collection of independent modules. Use it as a full application framework, or import only the packages you need.

Application framework

Runtime components required to build a complete application: entry facade, network communication, data access and common services.

Top-level package Sub-packages Description
frame/ g, gins Application facade and singleton container. g exposes global entry points such as g.Server(), g.DB() and g.Cfg(); gins handles singleton registration and core component instance management
net/ ghttp, gclient, gtcp, gudp, gipv4, gipv6 Network communication. ghttp provides routing, middleware, static files, WebSocket and graceful restart; gclient provides a chainable HTTP client; gtcp/gudp provide TCP/UDP server and client; gipv4/gipv6 provide IP address parsing and validation
database/ gdb, gredis Data access. gdb is a driver-agnostic ORM supporting models, transactions, soft delete, sharding and hooks; gredis defines the Redis client abstraction with single, cluster and sentinel modes
os/ gcfg, glog, gcache, gsession, gview, gcron, gtimer Application services. Config supports multiple formats and hot reload; logging supports leveled output, file rotation and trace context; cache provides in-memory LRU with expiry and pluggable adapters; session supports file, memory and Redis storage; template supports built-in functions and i18n; cron supports second-level schedules, intervals and one-shot timers

Service governance

Abstraction layer for microservice scenarios. It defines interfaces and common capabilities only; concrete implementations live in contrib/.

Top-level package Sub-packages Description
net/ gsvc, gsel, gtrace, goai gsvc defines service registry and discovery interfaces; gsel defines load-balancing selectors; gtrace wraps OpenTelemetry tracing; goai generates OpenAPI documents
os/ gmetric Metric abstraction layer defining Counter, UpDownCounter, Histogram and the observable variants ObservableCounter, ObservableUpDownCounter and ObservableGauge. See contrib/metric/otelmetric for the reporting implementation

Utility libraries

General-purpose capabilities that can be imported independently without the framework runtime.

Top-level package Sub-packages Description
os/ gfile, gfsnotify, gproc, grpool, gfpool, gctx, genv, gtime, gres, gspath, gstructs, gbuild, gcmd, gmlock, gmutex System and runtime utilities. File I/O, file watching, process management, goroutine pool, file pointer pool, context, environment variables, time handling, resource management, search path, struct reflection, build info, CLI parsing, memory lock, mutex
container/ garray, gmap, gset, glist, gqueue, gring, gtree, gpool, gtype, gvar Concurrent-safe containers. Array, map, set, list, queue, ring, tree, object pool, type wrapper and generic variable, all safe for concurrent access
encoding/ gjson, gyaml, gtoml, gini, gxml, gproperties, gbase64, gbinary, gcharset, gcompress, ghash, ghtml, gurl Codecs and format conversion. JSON, YAML, TOML, INI, XML and Properties parsing; Base64, binary, charset conversion, compression, hashing, HTML escaping and URL encoding
crypto/ gaes, gdes, grsa, gmd5, gsha1, gsha256, gsha512, gcrc32 Encryption and digests. AES and DES symmetric encryption, RSA asymmetric encryption, MD5, SHA1, SHA256 and SHA512 digests, CRC32 checksums
util/ gconv, gvalid, gmeta, gtag, gmode, gpage, grand, guid, gutil General utilities. Type conversion, validation, metadata, struct tags, run mode (develop, testing, staging, product), pagination, random numbers and unique IDs
text/ gstr, gregex Text processing. String search, replace, split and format; regex wrapper
errors/ gerror, gcode Error handling. gerror provides stack-aware error wrapping; gcode defines standard error codes
i18n/ gi18n Internationalization with multi-language resource loading and translation
debug/ gdebug Debug helpers for printing call stacks and variable information
test/ gtest Unit test helpers providing gtest.C blocks and fluent assertions

Ecosystem modules (contrib/)

Standalone modules that require a separate go get, grouped by domain.

Area Modules Description
Database drivers mysql, pgsql, mssql, oracle, sqlite, sqlitecgo, clickhouse, dm, gaussdb, mariadb, oceanbase, tidb Database driver implementations for gdb, registered into the framework via blank import
Config adapters apollo, consul, nacos, polaris, kubecm Remote config source adapters for gcfg, supporting config watching and hot reload
Service registry etcd, consul, nacos, polaris, zookeeper, file Service registry and discovery implementations for gsvc; file is a local file implementation suited for development and debugging
RPC grpcx gRPC-based RPC component integrating service registry, load balancing and tracing
Tracing / metrics otlpgrpc, otlphttp, otelmetric OpenTelemetry implementations for gtrace and gmetric, supporting both gRPC and HTTP exporters
Redis adapter redis Adapter implementation for gredis based on go-redis, also usable as the storage backend for gcache and gsession
SDK utilities httpclient HTTP client wrapper for SDK scenarios, supporting custom response handlers and request/response logging

Command-line tool

The gf CLI ships with GoFrame and covers daily development tasks such as project scaffolding, code generation, building and deployment.

Commonly used commands:

Command Description
gf init Create and initialize an empty GoFrame project
gf run Run Go code with hot-compiled-like behavior
gf gen dao Generate dao, do and entity code from database tables
gf gen ctrl Parse api definitions and generate controller and SDK code
gf build Cross-build the project for multiple platforms and architectures

See cmd/gf for the full command list and usage details.

Contributors

💖 Thanks to all the contributors who made GoFrame possible 💖

goframe contributors

License

GoFrame is licensed under the MIT License, 100% free and open-source, forever.

gf (gogf/gf)

正在搜索数据库…

13.3K ·GitHub
这是什么?GoFrame 是一个 Go 的开发框架:你可以在它的各个模块之上搭建后端项目,而不需要自己把所有东西拼起来。README 宣传它能让你开发得更快、更轻松、更高效。
它是我写代码时用的框架,还是我安装的应用?是一个框架——一组你可以导入自己项目的 Go 模块,不是面向最终用户的应用。这个仓库本身完全用 Go 编写。
我怎么把它加到我的项目里?参考 Installation(安装)部分,它会指引你到官方文档:把它作为你项目的 Go 模块依赖,按标准的 go get 流程安装。
使用它需要提前装好什么?只需要 Go 工具链。仓库本身用 Makefile 构建,CI 在 GitHub Actions 上配合 docker-compose 运行,但作为使用者,你只需要写 Go 就行。
文档只有中文的吗?不是——文档同时提供英文版和中文版:在最初的中文站之外还有官方英文站点、镜像站点、可下载的离线文档,以及 GoDoc API 参考手册。
我可以在商业项目中使用它吗?可以——它采用 MIT 许可证,而且 README 承诺会永远 100% 免费开源。
除了核心框架,它还包含什么?根据它的 GitHub 话题标签,它内置了 ORM、日志,以及基于 OpenTelemetry 的链路追踪和可观测性,并面向微服务开发,考虑了 Kubernetes 部署场景。
GoFrame 是成熟项目还是新的实验品?它从 2017 年起就在 GitHub 上,已经收获了超过 13,000 个 star;仓库运行 CI 流水线,包含 CodeQL 安全扫描,并强制执行代码格式化。
有哪些类似的项目?gofr, kratos, go-zero, encore, beego, echo, siglake, parlant
作者
gogf
大小
31.7 MB
星标
13.3K
时长
9年
提交 · 90 天