hertz-knowledge

Guides HTTP service development with the Hertz Golang framework including routing, middleware, and code generation.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill hertz-knowledge-yuezhen-huang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hertz-knowledge
Source: https://github.com/yuezhen-huang/my-bytedance-skillhub/tree/main/hertz-knowledge
Command: npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill hertz-knowledge-yuezhen-huang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Developers building HTTP services with ByteDance's Hertz framework need authoritative guidance on routing, parameter binding, middleware, IDL-driven code generation, and the Hertz 1.0 dual-context model, which is scattered across many internal documents. ## Core Features & Use Cases - Framework Onboarding: Covers installation, environment setup, and creating a first Hertz service with hertztool v3. - IDL-Driven Development: Explains Thrift/Protobuf annotations (api.query, api.path, api.body, api.vd) and code generation workflows with hertztool. - Request/Response API Reference: Details RequestContext usage, parameter binding and validation, middleware, TLS/HTTP2/WebSocket configuration, and HTTP client usage. - Use Case: A backend engineer needs to expose a RESTful CRUD API for a user service. They define a Thrift IDL with api.get/api.post annotations, run hertztool update to generate handlers and routes, implement business logic with BindAndValidate, and configure TLS and connection pooling following the best practices guide. ## Quick Start Ask the agent to explain how to create a new Hertz HTTP service with hertztool and define routes from a Thrift IDL file.

Frequently Asked Questions about hertz-knowledge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a new Hertz HTTP service with hertztool?

Install hertztool v3 with go install, then run hertztool new --psm=p.s.m --mod=your/module/path to scaffold the project. This generates main.go, handler and router directories, and a hertz.config.yaml; run go mod tidy and go run main.go to start the server on port 8888.

How to generate Hertz handler code from Thrift IDL?

Define your service in a Thrift file with api.get/api.post annotations on methods and api.query/api.path/api.body annotations on fields, then run hertztool update -idl idl/api.thrift --mod=your/module. Use --insert on first generation to create handler skeletons, and omit it later to protect handwritten code.

What is the difference between context.Context and RequestContext in Hertz 1.0?

Hertz 1.0 handlers receive both a standard context.Context and an app.RequestContext. The standard context is goroutine-safe and used for metadata propagation and timeouts, while RequestContext holds request/response data, is not goroutine-safe, and must be copied with ctx.Copy() before use in goroutines.

Does Hertz support HTTP/2 and TLS?

Yes, Hertz supports TLS via server.WithTLS with a tls.Config, and HTTP/2 is negotiated automatically through ALPN when TLS is enabled with server.WithALPN(true). Mutual TLS is supported by configuring ClientAuth and ClientCAs on the tls.Config.

Why is my Hertz RequestContext causing panics in goroutines?

RequestContext is not goroutine-safe and is recycled after the request ends, so accessing it concurrently causes data races or panics. Read needed values before spawning the goroutine, or call ctx.Copy() to obtain a safe copy for asynchronous use.

How do I validate request parameters in Hertz?

Use ctx.BindAndValidate(&req) with struct tags like query, path, json, and vd for validation rules. The vd tag accepts expressions such as len($)>0, email($), or numeric ranges like $>0 && $<=100, powered by the go-tagexpr binding framework.