grayscale

package
v1.65.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package grayscale 提供灰度路由:按比例或按用户稳定分流新旧版本处理器。 场景:新接口灰度发版(5% → 20% → 50% → 100%)、A/B 测试。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Strategy

type Strategy struct {
	// Ratio 命中新版本的比例(0~1);1 = 全量新版本,0 = 全量旧版本。
	Ratio float64
	// UserKey 提取用户标识的函数(nil = 按请求随机分流)。
	// 提供后同一用户始终命中同一版本(稳定灰度)。
	UserKey func(ctx iris.Context) string
}

Strategy 灰度策略。

func New

func New(ratio float64, userKey ...func(ctx iris.Context) string) *Strategy

New 创建灰度策略。userKey 可选(传入则用户稳定分流)。

func (*Strategy) Hit

func (s *Strategy) Hit(ctx iris.Context) bool

Hit 判断当前请求是否命中新版本。

func (*Strategy) Route

func (s *Strategy) Route(newHandler, oldHandler iris.Handler) iris.Handler

Route 返回分流中间件:命中走 newHandler,否则走 oldHandler。 用法:app.Get("/api/order", gray.Route(newOrderHandler, oldOrderHandler))

Jump to

Keyboard shortcuts

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