Skip to content
gogfPublic

About

A powerful framework for faster, easier, and more efficient project development.

Topics

Resources

Contributing

Stars

13.3k stars

Watchers

202 watching

Forks

Latest commit

 

History

6,581 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A powerful framework for faster, easier, and more efficient project development.

Topics

Resources

Contributing

Stars

13.3k stars

Watchers

202 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages