server

package
v0.0.1-beta.8 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package server 装配 chi 路由:/api/admin/*(platform_admin JWT 或该身份的管理 key mk-)+ /api/user/*(身份鉴权,register/login 公开)+ 三个 AI 端点 + /healthz。 架构约束:所有 API 统一收口于 /api/*,前端 SPA 占用根及 /api/user/*、/app/*, 两者无前缀重叠,SPA fallback 可无歧义地回 index.html。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UserIDFromContext

func UserIDFromContext(ctx context.Context) (int64, bool)

UserIDFromContext 取 /admin 鉴权路径注入的用户 id(JWT 或管理 key mk- 皆注入; 兑换码生成 created_by 用);未注入 → (0, false)。

Types

type Options

type Options struct {
	JWTIssuer *auth.Issuer // platform_admin JWT 鉴权(/api/admin 扩展)
	// Auth 单一鉴权快照面(users + mgmt 合并,proxy.Auth 实现):adminAuth 的
	// JWT 分支查用户快照(status+role+token_version),mk- 分支查管理 key + owner
	// 快照;nil = 两条路径全拒(fail-closed)。
	Auth              auth.SnapshotProvider
	MaxInflight       int64
	ReadHeaderTimeout time.Duration
	MaxHeaderBytes    int
	AdminHandler      http.Handler // 已挂 /api/admin/* 路由
	UserHandler       http.Handler // 已挂 /api/user/* 路由(内部完成公开/身份分流)
	// SupplierHandler 供应商面(/api/user/supplier/*):RequireJWT + 快照基
	// RequireRole(supplier|platform_admin) + 作用域注入 + **契约生成路由**
	// (openapi 里 tag `supplier` 的 path;未登记者未注册 ⇒ 404),账号/分组(只读)/
	// 模板(只读) op 转发到管理面同一批 handler(§2.5/§2.6)。nil = 不挂载。
	SupplierHandler http.Handler
	AIHandler       http.Handler // proxy 三个端点
	WebFS           fs.FS        // 前端构建产物(nil = 不挂静态资源)
	Logger          *logx.Logger
}

type Server

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

func NewServer

func NewServer(opts Options) *Server

func (*Server) Handler

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

Jump to

Keyboard shortcuts

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