runtime

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetConfig = &ServerRuntimeConfig{}

全局配置实例,按需加载。

Functions

func BuildServerFromConfig

func BuildServerFromConfig(cfg APIServerConfig) (*gin.Engine, error)

BuildServerFromConfig builds a gin engine from APIServerConfig. BuildServerFromConfig 根据 APIServerConfig 构建 gin engine。

func ConfigureGinMode

func ConfigureGinMode(explicitMode string) string

*

  • 配置Gin框架运行模式
  • 根据项目目录下特征文件决定运行模式。

func ExportTypesFromConfig added in v0.3.3

func ExportTypesFromConfig(cfg APIServerConfig) error

ExportTypesFromConfig exports TS files from APIServerConfig without building the server. ExportTypesFromConfig 根据 APIServerConfig 导出 TS 文件,但不构建服务。

func GetGinMode

func GetGinMode() string

*

  • 获取Gin框架运行模式
  • 根据项目目录下特征文件判断运行模式:
  • - 存在 node_modules 或 api_default.go 或 vue/pages/index.vue:开发模式(默认模式,输出详细日志)
  • - 不存在上述文件,但存在 vue/.output/public:生产模式(禁用详细日志,提高性能)
  • - 其它情况:生产模式

func LogServer

func LogServer()

func ResolveGinMode added in v0.3.3

func ResolveGinMode(explicitMode string) string

func RunServerFromConfig

func RunServerFromConfig(cfg APIServerConfig) error

RunServerFromConfig configures gin mode, logs server info, builds router, and runs it. RunServerFromConfig 会配置 gin mode、打印日志、构建路由并启动服务。

func ServeVue

func ServeVue(engine *gin.Engine)

*

  • 配置Vue应用服务
  • 根据当前Gin运行模式,选择不同的服务方式:
  • - 生产模式:直接提供静态文件服务
  • - 开发模式:通过反向代理连接到Vue开发服务器

func ServeVueDevelopment

func ServeVueDevelopment(engine *gin.Engine)

*

  • 开发环境Vue服务
  • 通过反向代理将请求转发到运行中的Nuxt开发服务器

func ServeVueProduction

func ServeVueProduction(engine *gin.Engine)

*

  • 生产环境Vue服务
  • 直接从打包后的静态文件目录提供服务

func SetActiveConfig added in v0.3.3

func SetActiveConfig(config ServerRuntimeConfig)

Types

type APIServerConfig

type APIServerConfig struct {
	// Server contains base URL and ports used by the runtime.
	// Server 包含运行时使用的基础 URL 与端口配置。
	Server ServerRuntimeConfig

	// GinMode controls debug/release mode. Empty means auto-resolve.
	// GinMode 控制 debug/release 模式;为空表示自动解析。
	GinMode string

	// CORS is the actual gin-contrib/cors config.
	// CORS 为 gin-contrib/cors 的实际配置;为 nil 表示不启用 CORS。
	CORS *cors.Config

	// API definitions (already include GroupPath/BasePath inside each API struct).
	// API 定义(各自结构体内已包含 GroupPath/BasePath)。
	ServerAPI    endpoint.ServerAPI
	WebSocketAPI endpoint.WebSocketAPI

	// Three TS output paths.
	// 三个 TS 输出路径。
	ServerTSPath    string
	WebSocketTSPath string
	SchemaTSPath    string

	// ExportUnifiedTS controls whether to export into three files via shared schema mode.
	// ExportUnifiedTS 控制是否使用共享 schema 的三文件统一导出。
	ExportUnifiedTS bool

	// ExportTSOnRun controls whether RunServerFromConfig exports TS before starting.
	// ExportTSOnRun 控制 RunServerFromConfig 是否在启动前导出 TS。
	ExportTSOnRun bool
}

APIServerConfig configures server runtime, API registration, and TS generation outputs. APIServerConfig 用于统一配置服务端口、API 注册和 TS 输出路径。

func DefaultAPIServerConfig

func DefaultAPIServerConfig(
	endpoints []endpoint.EndpointLike,
	wsEndpoints []endpoint.WebSocketEndpointLike,
) APIServerConfig

DefaultAPIServerConfig returns a fully initialized default config with endpoints. DefaultAPIServerConfig 返回一份可直接使用的默认配置,并注入 Endpoints。

type Config

type Config = ServerRuntimeConfig

Backward-compatible alias. 兼容旧命名 Config。

type ServerRuntimeConfig

type ServerRuntimeConfig struct {
	GinPort  int    `json:"ginPort"`  // Gin服务器端口
	NuxtPort int    `json:"nuxtPort"` // Nuxt应用端口
	BaseUrl  string `json:"baseUrl"`  // 应用基础URL
}

*

  • 运行时服务配置
  • 包含与前后端服务相关的配置参数

func LoadConfig added in v0.2.21

func LoadConfig() (*ServerRuntimeConfig, error)

LoadConfig loads and validates runtime config once. LoadConfig 按需加载并校验运行时配置。

func (*ServerRuntimeConfig) Acquire

func (config *ServerRuntimeConfig) Acquire() error

*

  • 从配置文件加载配置
  • 读取server.config.json文件并解析到Config结构体

func (ServerRuntimeConfig) Validate added in v0.2.21

func (config ServerRuntimeConfig) Validate() error

Validate checks whether the runtime config is safe to use. Validate 校验运行时配置是否合法。

Jump to

Keyboard shortcuts

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