server

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

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

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

README

Server

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

  • 创建 Echo 实例;
  • 注册基础 middleware;
  • 注册 /api/health/api/info
  • 提供业务路由入口 API()
  • 处理 HTTP 错误响应;
  • 管理启动和优雅关闭。

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

它不 import 业务模块。业务路由只在 internal/boot 里显式组装。System First Initialization gate 通过 WithInstallationStateReader 注入;server 只判断当前安装是否完成,并在未完成时放行 health/info/setup 路由、拦截普通管理路由,不知道 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.NewModuleboot.Provideboot.Route 声明 adapter、usecase、handler 和 route,让 boot 持有同一个 do dependency graph。

Documentation

Overview

Package server owns the Echo HTTP runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyIdentity

type APIKeyIdentity = middlewares.APIKeyIdentity

APIKeyIdentity is the server-owned identity shape returned by API key auth.

type APIKeyVerifier

type APIKeyVerifier = middlewares.APIKeyVerifier

APIKeyVerifier verifies API key credentials before browser session middleware runs.

type CapabilityStatus

type CapabilityStatus struct {
	Name      string `json:"name"`
	Enabled   bool   `json:"enabled"`
	Available bool   `json:"available"`
	State     string `json:"state"`
	Message   string `json:"message,omitempty"`
}

CapabilityStatus is the server-owned JSON shape for capability routes.

type Config

type Config struct {
	Port string

	ReadTimeout time.Duration

	WriteTimeout time.Duration

	IdleTimeout time.Duration

	ShutdownTimeout time.Duration

	HideBanner bool
}

Config contains HTTP server runtime settings.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default HTTP server settings.

func FromAppConfig

func FromAppConfig(cfg configs.Config) *Config

FromAppConfig derives HTTP server settings from application config.

type InstallationStateReader

type InstallationStateReader = middlewares.InstallationStateReader

InstallationStateReader reports first-initialization state to server middleware.

type LoginSessionAuthenticator

type LoginSessionAuthenticator = middlewares.LoginSessionAuthenticator

LoginSessionAuthenticator verifies browser login session cookies.

type LoginSessionIdentity

type LoginSessionIdentity = middlewares.LoginSessionIdentity

LoginSessionIdentity is the authenticated browser login session identity.

type Option

type Option func(*Server)

Option customizes the HTTP server.

func WithAPIKeyVerifier

func WithAPIKeyVerifier(verifier APIKeyVerifier) Option

WithAPIKeyVerifier installs optional API token authentication.

func WithInstallationStateReader

func WithInstallationStateReader(reader InstallationStateReader) Option

WithInstallationStateReader installs the uninitialized-system gate.

func WithLoginSessionAuthenticator

func WithLoginSessionAuthenticator(authenticator LoginSessionAuthenticator) Option

WithLoginSessionAuthenticator installs browser login-session authentication.

func WithStatusReporter

func WithStatusReporter(reporter StatusReporter) Option

WithStatusReporter installs the readiness and capability reporter.

func WithSystemErrorRecorder

func WithSystemErrorRecorder(recorder SystemErrorRecorder) Option

WithSystemErrorRecorder installs optional internal-error recording.

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.

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) []CapabilityStatus
	Ready(context.Context) error
}

StatusReporter supplies readiness and capability status to system routes.

type SystemErrorInput

type SystemErrorInput = middlewares.SystemErrorInput

SystemErrorInput is the server-owned diagnostic payload for internal errors.

type SystemErrorRecorder

type SystemErrorRecorder = middlewares.SystemErrorRecorder

SystemErrorRecorder stores internal API failure diagnostics.

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