Documentation
¶
Index ¶
- func BuildServerFromConfig(cfg APIServerConfig) (*gin.Engine, error)
- func ConfigureGinMode()
- func GetGinMode() string
- func LogServer()
- func RunServerFromConfig(cfg APIServerConfig) error
- func ServeVue(engine *gin.Engine)
- func ServeVueDevelopment(engine *gin.Engine)
- func ServeVueProduction(engine *gin.Engine)
- type APIServerConfig
- type Config
- type ServerRuntimeConfig
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 GetGinMode ¶
func GetGinMode() string
*
- 获取Gin框架运行模式
- 根据项目目录下特征文件判断运行模式:
- - 存在 node_modules 或 api_default.go 或 vue/pages/index.vue:开发模式(默认模式,输出详细日志)
- - 不存在上述文件,但存在 vue/.output/public:生产模式(禁用详细日志,提高性能)
- - 其它情况:生产模式
func RunServerFromConfig ¶
func RunServerFromConfig(cfg APIServerConfig) error
RunServerFromConfig configures gin mode, logs server info, builds router, and runs it. RunServerFromConfig 会配置 gin mode、打印日志、构建路由并启动服务。
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 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结构体
Click to show internal directories.
Click to hide internal directories.