runtime

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildServerFromConfig

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

BuildServerFromConfig builds a gin engine from APIServerConfig and exports TS if configured. BuildServerFromConfig 根据 APIServerConfig 构建 gin engine,并按配置导出 TS。

func ConfigureGinMode

func ConfigureGinMode()

*

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

func GetGinMode

func GetGinMode() string

*

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

func LogServer

func LogServer()

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服务
  • 直接从打包后的静态文件目录提供服务

Types

type APIServerConfig

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

	// 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
}

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
}

*

  • 运行时服务配置
  • 包含与前后端服务相关的配置参数
var GetConfig *ServerRuntimeConfig = func() *ServerRuntimeConfig {
	config := &ServerRuntimeConfig{}
	config.Acquire()
	return config
}()

全局配置实例,程序启动时初始化

func (*ServerRuntimeConfig) Acquire

func (config *ServerRuntimeConfig) Acquire()

*

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

Jump to

Keyboard shortcuts

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