static

package
v1.11.2 Latest Latest
Warning

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

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

README

集中管理静态资源(internal/static)

概述

internal/static 提供集中注册静态资源的帮助函数,避免在各个路由文件中重复调用 router.Static(...)group.Static(...)

提供的 API

  • RegisterStaticRoutes(router *gin.Engine, cfg *config.ConfigManager)
    • 在应用根上注册公共静态资源(/assets, /css, /js, /components)。

注意: 管理后台静态资源需要鉴权,已改为在 internal/routes/admin.go 中由受保护的处理器提供,避免在这里公开注册。

使用示例

internal/routes/base.go 中:

import "github.com/zy84338719/filecodebox/internal/static"

// ...
static.RegisterStaticRoutes(router, cfg)

internal/routes/admin.go 中:

import "github.com/zy84338719/filecodebox/internal/static"

// ...
static.RegisterAdminStaticRoutes(adminGroup, cfg)

扩展性

  • 如果需要添加缓存 header、CDN 前缀或将资源改为嵌入(embed),可以在此包中统一实现并将选项通过参数传入 Register* 函数。

注意

  • 本模块使用 cfg.ThemesSelect 与相对路径 ./<theme> 来定位资源,行为与历史实现一致。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStaticRoutes

func RegisterStaticRoutes(router *gin.Engine, cfg *config.ConfigManager)

RegisterStaticRoutes registers public-facing static routes (assets, css, js, components)

func ResolveThemeFile added in v1.8.2

func ResolveThemeFile(cfg *config.ConfigManager, parts ...string) (string, error)

ResolveThemeFile returns the concrete filesystem path for a theme file, applying fallbacks.

func ServeAdminPage

func ServeAdminPage(c *gin.Context, cfg *config.ConfigManager)

ServeAdminPage serves the admin index page

func ServeIndex

func ServeIndex(c *gin.Context, cfg *config.ConfigManager)

ServeIndex serves the main index page with basic template replacements.

func ServeSetup

func ServeSetup(c *gin.Context, cfg *config.ConfigManager)

ServeSetup serves the setup page with template replacements.

func ServeThemeFile added in v1.10.0

func ServeThemeFile(c *gin.Context, cfg *config.ConfigManager, parts ...string)

ServeThemeFile serves a theme file, falling back to embedded FS if filesystem path not found

func ServeUserPage

func ServeUserPage(c *gin.Context, cfg *config.ConfigManager, pageName string)

ServeUserPage serves user-facing static pages (login/register/dashboard/etc.)

func SetEmbeddedFS added in v1.10.0

func SetEmbeddedFS(efs embed.FS)

SetEmbeddedFS sets the embedded filesystem for static assets

func ThemePath added in v1.8.2

func ThemePath(cfg *config.ConfigManager, parts ...string) string

ThemePath returns the resolved theme directory joined with optional relative parts.

Types

This section is empty.

Jump to

Keyboard shortcuts

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