Example code

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

Server

Run hertz

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

Config

  • config :Example of configuring hertz server

Protocol

  • Protocol :Example of hertz using protocols such as HTTP1, TLS, etc

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

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

  • hlog: :Example of using hlog and its log extension

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

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 July 3, 2023 : Update response.md (604692d)