Example code

Hertz provides a series of code examples designed to help users get start with Hertz and be familiar with its features.

Hertz provides a series of code examples designed to help users get start with Hertz and be familiar with its features. Refer to hertz-examples for more information.

Bizdemo

hertz_gorm

  • hertz_gorm :Example of using gorm in hertz server

hertz_gorm_gen

  • hertz_gorm_gen :Example of using gorm/gen & proto IDL in hertz server

hertz_jwt

  • hertz_jwt :Example of using jwt in hertz server

hertz_session

  • hertz_session :Example of using distributed session and csrf in hertz server

tiktok_demo

  • tiktok_demo :A simple hertz server that provides user, video, interactive, and social backend services for tiktok app

hz_kitex_demo

Server

Run hertz

  • hello :Example of launching a hertz “hello world” application

Config

  • config :Example of configuring hertz server

Protocol

  • HTTP1 : Example of hertz using HTTP1 protocol
  • TLS : Example of hertz using TLS protocol
  • HTTP2 : Example of hertz using HTTP2 protocol
  • HTTP3 : Example of hertz using HTTP3 protocol
  • Websocket : Example of hertz using Websocket protocol
  • SSE : Example of hertz using SSE protocol

Route

  • Route :Examples of registering routes, using route groups, and parameter routes

Middleware

  • basic_auth :Example of using basic auth middleware
  • CORS :Example of using the CORS middleware
  • custom :Example of custom middleware
  • pprof :Example of using pprof middleware
  • requestid :Example of using RequestID middleware
  • gzip :Example of using gzip middleware in hertz server
  • csrf :Example of using csrf middleware in hertz server
  • loadbalance :Example of using loadbalance middleware in hertz server
  • Recovery :Example of using Recovery middleware
  • jwt :Example of using jwt middleware
  • i18n :Example of using i18n middleware
  • session :Example of using session middleware
  • KeyAuth :Example of using KeyAuth middleware
  • Swagger :Example of using Swagger middleware
  • access log :Example of using access log middleware
  • Secure :Example of using Secure middleware
  • Sentry :Example of using Sentry middleware
  • Casbin :Example of using Casbin middleware
  • ETag :Example of using ETag middleware
  • Cache :Example of using Cache middleware
  • Paseto :Example of using Paseto middleware

Parameter binding and validation

  • binding :Example of parameter binding and validation

Get Parameters

  • parameters :Example of getting query, form, cookie, etc. parameters

Documents

  • file :Examples of file upload, file download, and static file services

Render

  • render :Example of render body as json, html, protobuf, etc

Redirect

  • redirect :Example of a redirect to an internal/external URI

Streaming read/write

  • streaming :Example of streaming read/write using hertz server

Graceful shutdown

Unit test

  • unit_test :Example of writing unit tests using the interface provided by hertz without network transmission

Tracing

  • tracer :Example of hertz using Jaeger for link tracing

Monitoring

  • monitoring :hertz Example of metrics monitoring with Prometheus

Multiple service

Adaptor

  • adaptor :Example of using adaptor to integrate hertz with package built for http.Handler interface , including a demonstration on using jade as template engine.

Sentinel

  • sentinel :Example of using sentinel-golang in hertz

Reverse proxy

  • reverseproxy :Example of using reverse proxy in hertz server

Hlog

  • standard :Example of using Hertz’s default implementation for logging
  • custom :Example of log extension
  • zap :Example of docking with zap and lumberjack in hertz server
  • logrus :Example of docking with logrus and lumberjack in hertz server
  • zerolog :Example of docking with zerolog and lumberjack in hertz server
  • slog :Example of docking with slog and lumberjack in hertz server

Opentelemetry

  • opentelemetry :Example of using obs opentelemetry for docking with opentelemetry

HTTP Trailer

  • trailer :Example of using HTTP Trailer

Client

Send request

  • send_request :Example of sending an http request using the hertz client

Client config

TLS

  • tls :Example of hertz client sending a tls request

Add parameters

  • add_parameters :Example of adding request parameters using the hertz client

Upload file

  • upload_file :Example of uploading a file using the hertz client

Middleware

  • middleware :Example of using the hertz client middleware

Streaming read

  • streaming_read :Example of a streaming read response using the hertz client

Forward proxy

  • forward_proxy :Example of configuring a forward proxy using the hertz client

HTTP Trailer

  • trailer :Example of using HTTP Trailer

Hz

Generate server code based on Thrift

  • thrift :Example of using hz with thrift to generate server code

Generate server code based on Protobuf

  • protobuf :Example of using hz with protobuf to generate server code

Generate client code

  • hz_client :Example of using hz to generate client code

Custom templates

  • template :Example of using hz custom templates to generate server code

Three-party plugins

  • plugin :Example of using hz to access third-party plugins

Last modified October 17, 2024 : Fix multiple typos in shumei.md (#1159) (d3919b5)