server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 22 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 server 把 relay、channel 与 plugin 装配成一个可监听的 HTTP 服务, 对外暴露四种方言的端点。

装配规则只有一条:client 方言与渠道方言相同时按字节透传,不同时经 relay 转换。 插件在四个时机介入,插件失败不影响转发可用性。

Index

Constants

View Source
const SessionHeaderName = "X-TokenMP-Session"

SessionHeaderName 是客户端声明会话标识的请求头。

同一段会话的连续请求带上同一个值,core 会把它们粘到同一个上游渠道上,让上游 的提示缓存有机会命中。这个头只在本进程内使用,不会转发给上游。

Variables

This section is empty.

Functions

func BuildPlugins

func BuildPlugins(cfg *config.Config, logger *slog.Logger) (*plugin.Store, error)

BuildPlugins 按配置加载插件目录并构造插件集合。

插件目录不存在且没有启用任何插件时视为没有插件;启用了插件却找不到目录则报错, 否则「插件没生效」只能靠读日志发现。

Types

type Options

type Options struct {
	// Config 是配置,必填。
	Config *config.Config
	// Channels 是渠道客户端集合,必填。
	Channels *channel.Set
	// Plugins 是插件集合,为 nil 时视为没有插件。
	Plugins *plugin.Store
	// Engine 是转换内核,为 nil 时按配置构造。
	Engine *relay.Engine
	// Logger 是日志入口,为 nil 时丢弃日志。
	Logger *slog.Logger
	// Now 返回当前时间,为 nil 时用 time.Now。
	Now func() time.Time
	// MaxBodyBytes 是单个请求体的上限,为 0 时用 config.DefaultMaxBodyBytes。
	MaxBodyBytes int64
}

Options 是服务的装配参数。

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server 是一个转发服务。

func FromConfig

func FromConfig(cfg *config.Config, logger *slog.Logger) (*Server, error)

FromConfig 按配置装配渠道与插件,再创建服务。

配置里启用但目录里不存在的插件会直接报错:静默降级会让「插件没生效」变成 一个只能靠读日志发现的问题。

func New

func New(opts Options) (*Server, error)

New 创建服务。

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler 返回 HTTP 处理器,便于嵌入其它服务或直接做测试。

func (*Server) Listen

func (s *Server) Listen(ctx context.Context) (net.Listener, error)

Listen 按配置创建监听器。ctx 只影响监听建立阶段。

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run 监听并服务,直到 ctx 取消。ctx 取消后停止接收新连接并等待在途请求结束。

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, listener net.Listener) error

Serve 在给定监听器上服务,直到 ctx 取消。

Jump to

Keyboard shortcuts

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