Documentation
¶
Index ¶
- Variables
- func BuildServerFromConfig(cfg APIServerConfig) (*gin.Engine, error)
- func ConfigureGinMode(explicitMode string) string
- func ExportTypesFromConfig(cfg APIServerConfig) error
- func GetGinMode() string
- func LogServer()
- func ResolveGinMode(explicitMode string) string
- func RunServerFromConfig(cfg APIServerConfig) error
- func ServeVue(engine *gin.Engine)
- func ServeVueDevelopment(engine *gin.Engine)
- func ServeVueProduction(engine *gin.Engine)
- func SetActiveConfig(config ServerRuntimeConfig)
- type APIServerConfig
- type Config
- type ServerRuntimeConfig
Constants ¶
This section is empty.
Variables ¶
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 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 ResolveGinMode ¶ added in v0.3.3
func RunServerFromConfig ¶
func RunServerFromConfig(cfg APIServerConfig) error
RunServerFromConfig configures gin mode, logs server info, builds router, and runs it. RunServerFromConfig 会配置 gin mode、打印日志、构建路由并启动服务。
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 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 校验运行时配置是否合法。