server

package
v0.0.0-...-a7ad5ca Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

Server

internal/platform/server 只负责 Echo HTTP runtime:

  • 创建 Echo 实例;
  • 注册基础 middleware;
  • 注册 /api/health、/api/info、/api/ready、/api/capabilities(health 和 ready 同时注册 GET 与 HEAD 形式,服务 HEAD 探活);
  • 提供业务路由入口 API();
  • 处理 HTTP 错误响应;
  • 管理启动和优雅关闭。

/api/info 只返回静态配置里的 app.name、app.version 和当前时间。

它不 import 业务模块。业务路由只在 internal/boot 里显式组装。System First Initialization gate 通过 WithInstallationStateReader 注入;server 只判断当前安装是否完成并拦截未豁免路由,初始化前可达的路由名单由 boot 经 WithPreInitRoutes 注入,Login Session 的免认证名单经 WithUnauthenticatedRoutes 注入,server 不携带任何路由策略,也不知道 setup 表结构。API Token 认证通过 WithAPIKeyVerifier 传入一个小接口;server 只读取 X-API-Token、写入 request context,不知道 token 表、哈希策略或业务模块。浏览器 Login Session 认证通过 WithLoginSessionAuthenticator 注入;server 只读取 HttpOnly cookie 中的 opaque token、写入 request context,不知道会话表结构。内部错误记录通过 WithSystemErrorRecorder 注入,server 只在统一错误边界产生诊断事件,不知道审计表结构。

API

srv, err := server.New(cfg)
if err != nil {
	return err
}

if err := srv.Run(ctx); err != nil {
	return err
}

server.New 只接收静态配置值,不接收动态配置 store。业务路由不要在这里手写注册; 在 internal/boot 里用 boot.NewModule、boot.Provide 和 boot.Route 声明 adapter、usecase、handler 和 route,让 boot 持有同一个 do dependency graph。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

Option customizes the HTTP server.

func WithAPIKeyVerifier

func WithAPIKeyVerifier(verifier middlewares.APIKeyVerifier) Option

WithAPIKeyVerifier installs optional API token authentication.

func WithCSRFConfig

func WithCSRFConfig(config middleware.CSRFConfig) Option

WithCSRFConfig installs the auth-owned Echo CSRF configuration. CSRF activation still derives from login sessions: without an injected config the CSRF middleware is not installed.

func WithInstallationStateReader

func WithInstallationStateReader(reader middlewares.InstallationStateReader) Option

WithInstallationStateReader installs the uninitialized-system gate.

func WithLoginSessionAuthenticator

func WithLoginSessionAuthenticator(authenticator middlewares.LoginSessionAuthenticator) Option

WithLoginSessionAuthenticator installs browser login-session authentication.

func WithLoginSessionCookieName

func WithLoginSessionCookieName(name string) Option

WithLoginSessionCookieName installs the login-session cookie name. The name is Login Session domain policy declared by the auth module; the composition root injects it so the read and write sides share one declaration.

func WithPreInitRoutes

func WithPreInitRoutes(routes ...middlewares.RouteExemption) Option

WithPreInitRoutes installs routes that stay reachable before first initialization completes. The composition root derives them from its route exposure declaration.

func WithStatusReporter

func WithStatusReporter(reporter StatusReporter) Option

WithStatusReporter installs the readiness and capability reporter.

func WithSystemErrorRecorder

func WithSystemErrorRecorder(recorder middlewares.SystemErrorRecorder) Option

WithSystemErrorRecorder installs optional internal-error recording.

func WithUnauthenticatedRoutes

func WithUnauthenticatedRoutes(routes ...middlewares.RouteExemption) Option

WithUnauthenticatedRoutes installs routes reachable without a login session; CSRF exemptions derive from the same list. The composition root derives them from its route exposure declaration.

type Server

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

Server owns the Echo HTTP server lifecycle and system routes.

func New

func New(cfg configs.Config, opts ...Option) (*Server, error)

New creates an Echo-backed HTTP server. cfg must come from configs.Load, which owns normalization and validation; New trusts its input.

func (*Server) API

func (s *Server) API() *echo.Group

API returns the root API route group used by boot to register business routes.

func (*Server) Echo

func (s *Server) Echo() *echo.Echo

Echo returns the underlying Echo instance for HTTP adapter tests and framework-level integration.

func (*Server) Run

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

Run starts the HTTP server and blocks until ctx is canceled or startup fails.

type StatusReporter

type StatusReporter interface {
	Status(context.Context) []resources.CapabilityStatus
	Ready(context.Context) error
}

StatusReporter supplies readiness and capability status to system routes. The status record shape is owned by the infrastructure resources package, which also builds the only three legal states.

Directories

Path Synopsis
Package httpreq parses and validates Echo request inputs for HTTP adapters.
Package httpreq parses and validates Echo request inputs for HTTP adapters.
Package httpresp renders framework-specific HTTP error responses.
Package httpresp renders framework-specific HTTP error responses.
Package middlewares contains server-owned Echo middleware adapters.
Package middlewares contains server-owned Echo middleware adapters.

Jump to

Keyboard shortcuts

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