MCPcopy Create free account
hub / github.com/cloudwego/hertz-examples

github.com/cloudwego/hertz-examples @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
5,684 symbols 11,196 edges 373 files ⚖ custom 545 documented · 10% updated 16d ago★ 3481 open issues

Browse by type

Functions 5,164 Types & classes 520
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Hertz Examples

English | 中文

How to run

Enter an example directory for its specific run instructions. Unless an example says otherwise, run commands from the repository root.

Bizdemo

  • bizdemo/hertz_gorm: Use Thrift IDL, hz, Hertz binding and validation, GORM, and MySQL in a Hertz service.
  • bizdemo/hertz_jwt: Build a Hertz service with JWT authentication, GORM, and MySQL.
  • bizdemo/hertz_session: Use Redis-backed distributed sessions and CSRF protection in a Hertz service.
  • bizdemo/hertz_swagger_gen: Generate Swagger documentation and a Swagger UI service from Thrift IDL with thrift-gen-http-swagger.
  • bizdemo/tiktok_demo: A simple Hertz backend for user, video, social, feed, favorite, comment, and message services.
  • formulago: An enterprise administration framework built with Hertz and Ent.
  • gpress: A Web3 content platform built with Hertz and Go templates, with FTS5 full-text search and Hugo compatibility.

Server

  • hello: A basic Hertz “hello world” server.
  • config: Configure a Hertz server.
  • protocol: Use HTTP/1.1 and TLS with Hertz. It also links to external protocol examples.
  • HTTP1: A Hertz HTTP/1.1 server.
  • TLS: A TLS server plus a Hertz client that sends a TLS request.
  • HTTP2: The external Hertz HTTP/2 examples.
  • HTTP3: The external Hertz HTTP/3 example based on QUIC.
  • WebSocket: The external Hertz WebSocket examples.
  • SSE: A Hertz Server-Sent Events server and client using Hertz’s built-in SSE package.
  • middleware: Server middleware examples, including BasicAuth, CORS, CSRF, custom middleware, pprof, RequestID, Gzip, and load balancing.
  • basicauth: Use BasicAuth middleware.
  • CORS: Use CORS middleware.
  • csrf: Configure CSRF middleware, including custom token extraction and skip rules.
  • custom: Write and register custom middleware.
  • pprof: Configure pprof middleware.
  • requestid: Configure RequestID middleware and custom ID handling.
  • gzip: Configure Gzip compression and route/path exclusions.
  • loadbalance: Configure a non-default load-balancing algorithm.
  • Recovery: Use the built-in Recovery middleware.
  • JWT: Use JWT authentication middleware.
  • i18n: Use internationalization middleware.
  • session: Use session middleware with cookie or Redis backends.
  • KeyAuth: Authenticate requests with a configurable key lookup.
  • Swagger: Serve Swagger documentation with Hertz.
  • access log: Log HTTP access details.
  • Secure: Configure security-related HTTP headers and redirects.
  • Sentry: Report Hertz request errors to Sentry.
  • Casbin: Apply Casbin authorization middleware.
  • ETag: Add ETag response headers and customize ETag behavior.
  • Cache: Cache Hertz responses with memory or Redis backends.
  • Paseto: Protect routes with PASETO tokens.
  • binding: Bind request parameters and validate them.
  • parameters: Read query, form, and cookie parameters.
  • file: Upload and download files, serve static files, and render HTML from files or templates.
  • render: Render JSON, HTML, Protobuf, text, XML, and customized YAML responses.
  • redirect: Redirect requests to internal or external URIs.
  • route: Register static, grouped, parameterized, and middleware-protected routes, and inspect route metadata.
  • streaming: Stream request and response bodies from a Hertz server.
  • graceful_shutdown: Gracefully shut down a Hertz server.
  • unit_test: Test Hertz handlers with ResponseRecord and PerformRequest without network transmission.
  • monitoring: Export Hertz and Go runtime metrics to Prometheus and visualize them in Grafana.
  • opentelemetry: Trace a Hertz-to-Kitex request, export telemetry through OpenTelemetry Collector, and view traces and metrics in Jaeger and Grafana/VictoriaMetrics.
  • multiple_service: Run multiple Hertz services on different ports.
  • adaptor: Adapt standard-library http.Handler implementations for use in Hertz, including a Jade template example.
  • sentinel: Use Sentinel for traffic control with Hertz.
  • reverseproxy: Use the Hertz reverse proxy extension, with examples for standard proxying, TLS, discovery, response modification, SSE, middleware, and WebSocket.
  • hlog: Use Hertz logging and its logger extensions.
  • trailer: Read and write HTTP trailers with Hertz.
  • graphql-go: Serve GraphQL requests from a Hertz server.

Client

Hz

  • hz/thrift: Use hz with Thrift IDL to generate server code.
  • hz/protobuf: Use hz with Protobuf IDL to generate server code.
  • hz/hz_client: Use hz to generate client code.
  • hz/template: Use a custom hz template to generate a server project.
  • hz/plugin: Use third-party hz code-generation plugins with Thrift and Protobuf projects.
  • hz/struct_reuse: Reuse Kitex-generated Thrift structs as Hertz models.

Note

Commands for an example should be run from the hertz-examples repository root unless that example’s own README says otherwise.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 3,887
Function 1,277
Struct 476
Interface 36
FuncType 4
TypeAlias 4

Languages

Go94%
TypeScript6%

Modules by API surface

bizdemo/hertz_swagger_gen/biz/hertz_gen/openapi/openapi.go1,495 symbols
hz/plugin/proto/biz/model/github.com/google/gnostic/openapiv3/OpenAPIv3.pb.go856 symbols
bizdemo/hertz_swagger_gen/biz/hertz_gen/user/user.go259 symbols
bizdemo/hertz_gorm/biz/hertz_gen/user_gorm/api.go242 symbols
hz_kitex_demo/kitex-server/kitex_gen/student/management/student_management.go142 symbols
hz_kitex_demo/hertz-server/kitex_gen/student/management/student_management.go142 symbols
bizdemo/hertz_session/static/javascript/jquery.js112 symbols
bizdemo/hertz_session/biz/model/user/user.go110 symbols
hz_kitex_demo/hertz-server/biz/model/api/student_api.go106 symbols
bizdemo/hertz_session/static/javascript/bootstrap.bundle.js98 symbols
bizdemo/tiktok_demo/biz/model/social/relation/relation.pb.go87 symbols
bizdemo/hertz_session/static/javascript/jquery.min.js81 symbols

Datastores touched

(mysql)Database · 1 repos

For agents

$ claude mcp add hertz-examples \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page