adaptor

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 11 Imported by: ? 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

Index

Constants

View Source
const ProviderAPIVersion = 1

ProviderAPIVersion 是本 registry 暴露的 provider 契约版本(PRD §5.9)。 主仓 registry 接口(Register/MustRegister/Get/RegisteredAPITypes 的签名与语义) 发生不兼容变更时必须递增此值;扩展方在 init() 注册时应断言与本值一致, 不一致则启动期即报错。本阶段只定义常量与语义,断言方随扩展方接入落地。

Variables

This section is empty.

Functions

func DoRequest

func DoRequest(c *gin.Context, req *http.Request) (*http.Response, error)

func DoRequestHelper

func DoRequestHelper(a Adaptor, c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)

func IsExcludedRequestHeader added in v1.0.1

func IsExcludedRequestHeader(key string) bool

IsExcludedRequestHeader 检查指定头是否应被排除透传。 对外暴露,供其他 package(如 proxy adaptor)使用。

func MustRegister added in v1.0.1

func MustRegister(apiType int, factory func() Adaptor)

MustRegister 允许覆盖已登记的 apiType,绕过 Register 的重复注册保护。 仅供测试显式覆盖使用;生产代码必须使用 Register。

func Register added in v1.0.1

func Register(apiType int, factory func() Adaptor)

Register 以内置权威语义登记一个 adaptor 工厂。 同一 apiType 重复注册属于启动期的代码错误(内置注册只会发生一次), 因此直接 panic 并在信息中带上冲突的 apiType 数值,让错误尽早暴露。

func RegisteredAPITypes added in v1.0.1

func RegisteredAPITypes() []int

RegisteredAPITypes 按注册顺序返回已登记的 apiType(PRD §5.8 保序)。

func SetupCommonRequestHeader

func SetupCommonRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta)

SetupCommonRequestHeader 全量透传客户端请求头到上游请求, 排除不应转发的头(hop-by-hop、IP 泄露、认证等)。

各 adaptor 应在此函数之后设置各自认证头,覆盖排除后的值。

func Unregister added in v1.0.1

func Unregister(apiType int)

Unregister 从注册表中移除指定 apiType(对称于 Register / MustRegister,同样加写锁)。

供本仓测试使用:验证「扩展渠道被正确枚举」之类的行为需要临时注册一个 apiType, 测试收尾必须能把它清理干净,否则会污染同一进程内其它测试(例如断言注册表项数的 registry_test.go)。这与 channeltype.UnregisterAPIType 提供的清理能力保持一致。

对未登记的 apiType 调用本函数为空操作(不 panic);apiType 不在 order 列表中的 异常情形同样安全(仅删 map 项,不触碰 order)。

Types

type Adaptor

type Adaptor interface {
	Init(meta *meta.Meta)
	GetRequestURL(meta *meta.Meta) (string, error)
	SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error
	ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)
	ConvertImageRequest(request *model.ImageRequest) (any, error)
	DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)
	DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (usage *model.Usage, err *model.ErrorWithStatusCode)
	GetModelList() []string
	GetChannelName() string
}

func Get added in v1.0.1

func Get(apiType int) Adaptor

Get 返回 apiType 对应的 adaptor 实例;未命中时返回 nil (与改造前 switch 落空隐式返回 nil 的行为完全一致)。 factory 调用被 recover 包裹:单个渠道 panic 不会带崩进程,转为返回 nil 并记录错误日志(PRD §5.10)。

Directories

Path Synopsis
aws
claude
Package aws provides the AWS adaptor for the relay service.
Package aws provides the AWS adaptor for the relay service.
llama3
Package aws provides the AWS adaptor for the relay service.
Package aws provides the AWS adaptor for the relay service.

Jump to

Keyboard shortcuts

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