known

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package known 定义了一些供整个项目使用的常量. 通过使用这些常量,可以确保在整个项目中一致地引用这些特定的上下文键,从而提高代码的可读性和可维护性.

Index

Constants

View Source
const (
	// XRequestID 用来定义上下文中的键,代表请求 ID.
	XRequestID = "x-request-id"

	// XUserID 用来定义上下文的键,代表请求用户 ID. UserID 整个用户生命周期唯一.
	XUserID = "x-user-id"

	// XUsername 用来定义上下文的键,代表请求用户名.
	XUsername = "x-username"
)

定义 HTTP/gRPC Header. gRPC 底层使用了 HTTP/2 作为传输协议,而 HTTP/2 的规范 规定 Header 的键必须是小写的。因此,在 gRPC 中,所有的 Header 键都会被强制转换为小写, 以符合 HTTP/2 的要求。HTTP/1.x 中,许多 HTTP/1.x 的实现会保留用户设置的大小写格式 但一些 HTTP 框架或工具库(比如某些 web 服务器或代理)可能会自动将 Header 转为小写, 以简化处理逻辑. 考虑兼容性这里统一将 Header 设置为小写. 另外,Header 的键以 x- 开头,说明是自定义 Header.

View Source
const (
	// Admin 用户名.
	AdminUsername = "root"

	// MaxErrGroupConcurrency 定义了 errgroup 的最大并发任务数量.
	// 用于限制 errgroup 中同时执行的 Goroutine 数量,从而防止资源耗尽,提升程序的稳定性.
	// 根据场景需求,可以调整该值大小.
	MaxErrGroupConcurrency = 1000
)

定义其他常量.

View Source
const (
	// Role for regular users.
	RoleUser = "role::user"
	// Role for administrators.
	RoleAdmin = "role::admin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL