English | 中文
Enter an example directory for its specific run instructions. Unless an example says otherwise, run commands from the repository root.
- 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.
- 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
ResponseRecordandPerformRequestwithout 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.Handlerimplementations 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/send_request: Send requests with the Hertz client, including deadlines, redirects, and timeouts.
- client/config: Configure a Hertz client.
- protocol/tls: Send a TLS request with the Hertz client to the example TLS server.
- client/add_parameters: Add query, form, path, and body parameters to Hertz client requests.
- client/upload_file: Upload files with the Hertz client.
- client/middleware: Use client middleware.
- client/streaming_read: Read a streaming response with the Hertz client.
- client/forward_proxy: Configure a forward proxy for the Hertz client.
- trailer: Send a request and read its HTTP trailer with the Hertz client.
- hz/thrift: Use
hzwith Thrift IDL to generate server code. - hz/protobuf: Use
hzwith Protobuf IDL to generate server code. - hz/hz_client: Use
hzto generate client code. - hz/template: Use a custom
hztemplate to generate a server project. - hz/plugin: Use third-party
hzcode-generation plugins with Thrift and Protobuf projects. - hz/struct_reuse: Reuse Kitex-generated Thrift structs as Hertz models.
Commands for an example should be run from the hertz-examples repository root unless that example’s own README says otherwise.