aicodcms

command module
v0.0.0-...-9f83ea1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 29 Imported by: 0

README

aicodcms

Go 语言新一代 CMS | 插件化架构 | 双模板引擎 | 多语言站群

Go Version License


为什么选择 aicodcms

aicodcms 是一套用 Go 语言从头构建的 CMS 系统。它不是一个 WordPress 的克隆,也不是某个 PHP CMS 的 Go 移植——它从架构层面重新审视了「内容管理系统」应该是什么样子。

核心设计理念只有一条:权限管理是骨架,内容管理是血肉,插件是器官。


1. 核心架构

┌──────────────────────────────────────────┐
│            Vue 3 管理后台                 │
├──────────────────────────────────────────┤
│    Casbin RBAC  ─── PMS 权限引擎         │
├──────────────────────────────────────────┤
│  Account │ CMS │ Order │ Product │ ...   │
├──────────────────────────────────────────┤
│  Pay │ Mail │ Upload │ Sitemap │ ...     │  插件
├──────────────────────────────────────────┤
│        GoFrame v2 框架                    │
├──────────────────────────────────────────┤
│        MySQL 8.x                         │
└──────────────────────────────────────────┘
PMS:不可动摇的核心

所有功能模块——无论是 CMS、Order、还是任何一个插件——都通过 PMS 的 Casbin 引擎获得权限。删除任何业务模块都不会影响系统运行,但 PMS 是整个系统的骨架。

这意味着 aicodcms 可以是一个博客、一个商城、一个游戏后台、或者三者同时——只需加载不同的插件。

插件注入机制
// 每个模块只需实现 Plugin 接口
type Plugin interface {
    Name() string
    Migrations() []string                // 数据库迁移
    InitRouter(group *ghttp.RouterGroup) // 路由注册
}

// init() 中注册,主路由零 import 感知
func init() { plugin.Register(&cmsPlugin{}) }

主路由通过名称查找插件,不硬编码任何 import。添加新模块不需要修改一行框架代码。


2. 多语言支持

不只是字符串翻译

aicodcms 的多语言不是简单的「字典查表」。它是站群级别的多语言体系

  • zh-CN / en-US 双语言激活:框架声明 34 种语言,通过激活机制按需启用
  • 前端 + 后端统一 i18n:Vue 端用 $t(),Go 端用 g.I18n().Tf(),共用 TOML 翻译文件
  • 文章级多语言:每篇文章可以有独立的翻译版本,存储在 article_translationtopic_translation 两表中
  • URL 级别的多语言/zh-CN/article/123/en-US/article/123 各自独立
  • Sitemap hreflang:自动生成多语言 SEO 标签
翻译联动机制

CMS 文章保存时,自动触发翻译服务:

Article Add/Edit → Translation.SaveArticleTranslation()
  ├── 百度翻译 API → 自动机翻
  ├── 缓存(下次编辑同一篇不重新翻译)
  └── 手动覆盖(人工翻译优先)

Translation 是共享服务层,不暴露独立 API——它被 Article、Channel、Tag、Page 等所有内容模块内部调用。这种设计让最终用户无需关心「翻译管理」这个独立概念——翻译就是内容编辑的一部分。


3. 模板函数体系

对标帝国 CMS 标签,但有类型安全

aicodcms 的模板引擎灵感来自帝国 CMS 的标签系统,但去掉了所有魔法字符串:

帝国 CMS:  [!--title--]  [!--classname--]  [!--pageurl--]
aicodcms:  .Title        .ChanName         .PageUrl

每一个字段都是 Go 的方法调用,有编译期类型检查。不存在拼错标签名导致的运行时空白。

CmsCtx:双引擎共用的上下文
// 一个 CmsCtx 实例同时服务 gview 和 templ
ctx := NewCmsCtx("zh-CN")

// 文章查询
ctx.ArticleList(channelID, 10)   // 栏目文章列表(自动分页)
ctx.BlockArticle("home_slider")  // 区块文章
ctx.SearchArticle("关键词", 10)  // 全文搜索

// 上一篇 / 下一篇(无需手动写 SQL)
ctx.PrevUrl    ctx.PrevTitle
ctx.NextUrl    ctx.NextTitle

// URL 生成
ctx.ArticleUrl(id)  // /zh-CN/article/123.html
ctx.ChanUrl(id)     // /zh-CN/channel/5
ctx.PageUrl(id)     // /zh-CN/page/about

// 当前文章
ctx.Article.Id     ctx.Article.Title     ctx.Article.Content
ctx.Article.Views  ctx.Article.Price     ctx.Article.Tags

// 分页
ctx.PageHtml       // 分页 HTML,直接输出
ctx.TotalPages     ctx.CurrentPage

// 国际化
ctx.T("menu_home")     // 翻译
ctx.FormatTime(ts)     // 时间格式化
ctx.SubStr(s, 200)     // 截取

关键设计:所有查询结果都带缓存。 ArticleList 在同一请求中被多次调用时,只执行一次 SQL。模板作者不需要关心性能——引擎帮你做了 L1(请求级)和 L2(进程级)两层缓存。


4. 双模板引擎

为什么需要两套引擎
场景 推荐引擎 原因
设计师做页面 gview 熟悉的 HTML 语法,零学习成本
开发者做页面 templ Type-Safe,编译期错误检查
高性能站群 templ 编译到二进制,零文件 IO
热更新模板 gview 修改文件即时生效,无需重启
生产环境 templ 模板不可篡改,安全
开发环境 gview 改模板即刷新,高效
gview 引擎

Go 标准模板语法,模板文件放在 resource/template/cms/theme/{主题名}/

{{ $ctx := .Init . }}
<h1>{{ $ctx.SiteName }}</h1>
{{ range $ctx.ArticleList 2 10 }}
    <a href="{{ $ctx.ArticleUrl .Id }}">{{ .Title }}</a>
{{ end }}
  • 支持 {主题名}/ 下的无限子目录
  • 修改文件无需重启(开发模式)
  • 完整的 gview 函数体系(条件、循环、管道、自定义函数)
templ 引擎

templ 是 Go 生态的新一代 HTML 模板引擎——模板在编译期被转译为 Go 代码。

templ ArticleDetail(ctx *tpl.CmsCtx) {
    <article>
        <h1>{ ctx.Article.Title }</h1>
        @tpl.Raw(ctx.Article.Content)
    </article>
}
  • 编译期类型检查——永远不会出现「忘了传变量」的运行时错误
  • 编译到二进制——生产环境零文件 IO,无路径遍历风险
  • GoLand 原生支持——自动补全、语法高亮、跳转定义
  • 和 gview 共享同一套 CmsCtx API——切换引擎不改模板逻辑
双引擎切换

在后台选择主题时,系统自动检测模板文件类型:

主题目录
├── layout.html     → gview 引擎
└── layout.templ    → templ 引擎

一套系统,两种渲染方式。用户根据需要选择,不需要改任何配置。


5. 其他技术亮点

静态页面生成
  • MakeHtml:gcron 定时全站静态化 + 手动触发
  • 文章详情、列表、栏目、标签、单页——全部 .html 输出
  • 发布即刻生成,爬虫友好
灵活的内容模型
model_id = 1 → 文章(cms_article_topic 存正文)
model_id = 2 → 下载(cms_article_topic_down 存下载信息)
model_id = 3 → 电影(cms_article_topic_movie 存播放信息)

一个 article 表,三种扩展,用 model_id 区分。新增内容类型只需加一张扩展表,不动主表。

数据库设计
  • 软删除deleted_at 字段,GoFrame 自动处理
  • Snowflake UID:分布式唯一,不依赖自增 ID
  • 原子余额扣减UPDATE SET balance = balance - ? WHERE balance >= ?,防超卖
  • SQLite 支持:开发环境可用 SQLite 替代 MySQL
通用订单系统

order 表用 module 字段区分来源:

module = "game"     → 游戏 SDK 订单
module = "product"  → 商品订单
module = "article"  → 付费文章

一套订单模型,所有业务共享。新增业务类型不需要新建订单表。

API 响应规范
{ "code": 0, "msg": "ok", "data": { ... } }

所有接口统一响应格式,前端无需区分不同模块的返回结构。


快速开始

# 数据库
mysql -u root -p < sql/aicodcms.sql

# 编译
go build -o aicodcms .

# 运行
./aicodcms

后台:http://localhost:8201
账户:admin / 123456


文档

文档 说明
数据库字典 全量表结构
模板函数 gview + templ API
架构 & 功能边界 模块分层

私有扩展

[game] 游戏管理 · [SDK Gateway] 认证 · [Ban] 封禁 · [Google/Apple Pay]

aicodcms-pro

协议

MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1/addon/backup
Package backup provides the backup addon API request/response types.
Package backup provides the backup addon API request/response types.
v1/addon/mail
Package mail defines the API request/response structures for the mail module.
Package mail defines the API request/response structures for the mail module.
v1/addon/sitemap
Package sitemap defines the API request and response structures for the Sitemap SEO addon module.
Package sitemap defines the API request and response structures for the Sitemap SEO addon module.
v1/addon/upload
Package upload defines the API request and response structures for the file upload addon module.
Package upload defines the API request and response structures for the file upload addon module.
v1/cms/admin
Package admin defines the API request and response structures for CMS admin management endpoints.
Package admin defines the API request and response structures for CMS admin management endpoints.
v1/cms/home
Package home defines the API request and response structures for CMS frontend/public endpoints.
Package home defines the API request and response structures for CMS frontend/public endpoints.
v1/pms
Package pms defines the API request and response structures for the PMS (Permission Management System) module.
Package pms defines the API request and response structures for the PMS (Permission Management System) module.
internal
addon/backup/controller
Package backup provides the backup addon controller.
Package backup provides the backup addon controller.
addon/backup/data
Package data provides data transfer objects for the backup addon.
Package data provides data transfer objects for the backup addon.
addon/backup/logic/backup
Package backup provides the backup business logic including native and mysqldump drivers.
Package backup provides the backup business logic including native and mysqldump drivers.
addon/backup/router
Package router provides the backup addon route registration.
Package router provides the backup addon route registration.
addon/backup/service
Package service provides the backup addon service interface.
Package service provides the backup addon service interface.
addon/job/logic/task
Package task provides scheduled task function implementations for the job addon.
Package task provides scheduled task function implementations for the job addon.
addon/mail/consts
Package consts defines error codes for the mail module.
Package consts defines error codes for the mail module.
addon/mail/controller
Package controller defines the HTTP API handlers for the mail module.
Package controller defines the HTTP API handlers for the mail module.
addon/mail/data
Package data defines input and output data structures for the mail module.
Package data defines input and output data structures for the mail module.
addon/mail/logic
Package mail implements the mail send log service (addon_mail_log CRUD).
Package mail implements the mail send log service (addon_mail_log CRUD).
addon/mail/router
Package router defines route bindings for the mail module.
Package router defines route bindings for the mail module.
addon/mail/service
Package service defines the service interfaces for the mail module (send + log query).
Package service defines the service interfaces for the mail module (send + log query).
addon/mq/logic/mq
Package mq provides a pluggable message queue abstraction with support for Redis, in-memory gqueue, and RabbitMQ (stub) adapters.
Package mq provides a pluggable message queue abstraction with support for Redis, in-memory gqueue, and RabbitMQ (stub) adapters.
addon/mq/service
Package service defines the message queue service interface and types used across the mq addon.
Package service defines the message queue service interface and types used across the mq addon.
addon/pay/controller
Package controller provides the HTTP controller layer for payment operations.
Package controller provides the HTTP controller layer for payment operations.
addon/pay/logic/driver
Package driver defines the payment channel driver interface and provides Alipay & WeChat Pay implementations.
Package driver defines the payment channel driver interface and provides Alipay & WeChat Pay implementations.
addon/pay/router
Package router registers payment module HTTP routes.
Package router registers payment module HTTP routes.
addon/sitemap/logic/sitemap
Package sitemap provides sitemap generation, management, and search-engine URL pushing functionality.
Package sitemap provides sitemap generation, management, and search-engine URL pushing functionality.
app/cms/controller/admin
Package admin provides CMS admin controllers for link management.
Package admin provides CMS admin controllers for link management.
app/cms/controller/home
Package home provides CMS frontend RSS feed controller.
Package home provides CMS frontend RSS feed controller.
app/cms/data
Package data defines the input/output data structures for the CMS module (articles, channels, pages, tags, etc.).
Package data defines the input/output data structures for the CMS module (articles, channels, pages, tags, etc.).
app/cms/logic/cmsblock
Package cms_block provides CMS block management: CRUD, caching, translation, and listing.
Package cms_block provides CMS block management: CRUD, caching, translation, and listing.
app/cms/logic/cmslink
Package cmslink provides CMS link management: CRUD, listing, and cache operations.
Package cmslink provides CMS link management: CRUD, listing, and cache operations.
app/cms/logic/cmsrevision
Package cmsrevision provides article revision management.
Package cmsrevision provides article revision management.
app/cms/logic/cmssetting
Package cms_setting 配置管理 - 字段/分组 CRUD
Package cms_setting 配置管理 - 字段/分组 CRUD
app/cms/logic/common
Package common provides shared CMS rendering and cache helper functions.
Package common provides shared CMS rendering and cache helper functions.
app/cms/logic/doc
Package doc provides static document (HTML) generation and management for CMS content.
Package doc provides static document (HTML) generation and management for CMS content.
app/cms/logic/page
Package page provides single page management: CRUD, caching, translation, and listing.
Package page provides single page management: CRUD, caching, translation, and listing.
app/cms/logic/seo
Package seo provides SEO analysis logic for articles.
Package seo provides SEO analysis logic for articles.
app/cms/logic/tpl
Package tpl provides CmsCtx, the unified template context for both gview and Templ engines, offering shared data queries, i18n, formatting, and URL APIs.
Package tpl provides CmsCtx, the unified template context for both gview and Templ engines, offering shared data queries, i18n, formatting, and URL APIs.
app/cms/middleware
Package middleware provides search engine crawler detection middleware based on spider User-Agent matching and IP-based verification (CIDR + DNS reverse lookup).
Package middleware provides search engine crawler detection middleware based on spider User-Agent matching and IP-based verification (CIDR + DNS reverse lookup).
app/cms/middleware/hotlayer
Package hotlayer 爬虫来访热层 爬虫请求 → 去重+计数(不阻塞) → Worker 定时同步 MySQL
Package hotlayer 爬虫来访热层 爬虫请求 → 去重+计数(不阻塞) → Worker 定时同步 MySQL
app/cms/theme/icodcod
templ: version: v0.3.1020
templ: version: v0.3.1020
app/cms/tplbridge
Package tplbridge — Templ rendering bridge (isolated to break tpl↔icodcod import cycle)
Package tplbridge — Templ rendering bridge (isolated to break tpl↔icodcod import cycle)
app/order/consts
Package consts defines error code constants for the order module.
Package consts defines error code constants for the order module.
app/order/logic/order
Package order implements order business logic including listing, closing, manual refund, and resend notification for different modules (game/recharge/cms).
Package order implements order business logic including listing, closing, manual refund, and resend notification for different modules (game/recharge/cms).
app/order/logic/refund
Package refund implements refund business logic for Google Play and App Store voided/refund order listing.
Package refund implements refund business logic for Google Play and App Store voided/refund order listing.
app/pms/controller
Package controller implements the HTTP request handlers for PMS (Permission Management System) module.
Package controller implements the HTTP request handlers for PMS (Permission Management System) module.
app/pms/data
Package data defines the input/output data structures and pagination helpers for the PMS module.
Package data defines the input/output data structures and pagination helpers for the PMS module.
app/pms/logic
Package logic registers all PMS business logic sub-packages for initialization.
Package logic registers all PMS business logic sub-packages for initialization.
app/pms/logic/dept
Package dept implements department CRUD, cached list retrieval, and tree-structure building.
Package dept implements department CRUD, cached list retrieval, and tree-structure building.
app/pms/logic/dictdata
Package dict_data implements dictionary data CRUD with cache-through and default-value marking.
Package dict_data implements dictionary data CRUD with cache-through and default-value marking.
app/pms/logic/dicttype
Package dict_type implements dictionary type CRUD with uniqueness checks and cascading data updates.
Package dict_type implements dictionary type CRUD with uniqueness checks and cascading data updates.
app/pms/logic/middleware
Package middleware provides HTTP middleware for authentication, context initialization, and permission enforcement in the PMS module.
Package middleware provides HTTP middleware for authentication, context initialization, and permission enforcement in the PMS module.
app/pms/logic/operlog
Package operlog implements the operation log recording (via HTTP hook) and querying service for admin audit trails.
Package operlog implements the operation log recording (via HTTP hook) and querying service for admin audit trails.
app/pms/logic/param
Package param implements system parameter CRUD with key-uniqueness guard and cache-through retrieval.
Package param implements system parameter CRUD with key-uniqueness guard and cache-through retrieval.
app/pms/logic/pmscontext
Package pms_context implements the per-request context management for PMS, storing the currently logged-in user and providing typed accessors.
Package pms_context implements the per-request context management for PMS, storing the currently logged-in user and providing typed accessors.
app/pms/logic/role
Package role implements role CRUD, Casbin policy management, and cached role list retrieval.
Package role implements role CRUD, Casbin policy management, and cached role list retrieval.
app/pms/logic/rule
Package rule implements menu/rule CRUD, cached menu-tree building, and Casbin policy binding.
Package rule implements menu/rule CRUD, cached menu-tree building, and Casbin policy binding.
app/pms/logic/section
Package section implements post/section CRUD and active-section query for user assignment.
Package section implements post/section CRUD and active-section query for user assignment.
app/pms/logic/sysUserOline
Package sysUserOline manages admin user online status: saving, checking liveness, and forced logout.
Package sysUserOline manages admin user online status: saving, checking liveness, and forced logout.
app/pms/logic/user
Package user implements admin user authentication, CRUD, role/menu/permission query, and post assignment for the PMS module.
Package user implements admin user authentication, CRUD, role/menu/permission query, and post assignment for the PMS module.
app/product/controller
Package controller implements HTTP handlers for product management including product CRUD, SKU management, translation management, and recycle bin operations.
Package controller implements HTTP handlers for product management including product CRUD, SKU management, translation management, and recycle bin operations.
app/product/logic/product
Package product implements product business logic including CRUD operations, SKU management, translation management, and recycle bin for soft-deleted records.
Package product implements product business logic including CRUD operations, SKU management, translation management, and recycle bin for soft-deleted records.
app/translation/data
Package data defines data transfer objects for the translation module, including the machine translation (Translate) DTOs and the Baidu Translate API response types.
Package data defines data transfer objects for the translation module, including the machine translation (Translate) DTOs and the Baidu Translate API response types.
app/translation/logic
Package translation implements multi-language translation logic for articles, channels, pages, blocks, and dynamic content (EAV).
Package translation implements multi-language translation logic for articles, channels, pages, blocks, and dynamic content (EAV).
app/translation/logic/translate
Package translate provides a pluggable machine translation driver framework.
Package translate provides a pluggable machine translation driver framework.
app/translation/service
Package service defines the translation service interface and data types for multi-language content (articles, channels, pages, blocks, and EAV).
Package service defines the translation service interface and data types for multi-language content (articles, channels, pages, blocks, and EAV).
cmd
consts
Package consts provides shared constants for the codcms project.
Package consts provides shared constants for the codcms project.
plugin
Package plugin defines the core plugin system for aicodcms.
Package plugin defines the core plugin system for aicodcms.
library
i18n
Package i18n HTTP Accept-Language negotiation per RFC 7231 Language catalog follows BCP 47 / RFC 5646 tags (ISO 639-1 + ISO 3166-1 Alpha-2)
Package i18n HTTP Accept-Language negotiation per RFC 7231 Language catalog follows BCP 47 / RFC 5646 tags (ISO 639-1 + ISO 3166-1 Alpha-2)
i18nerr
Package i18nerr provides i18n-aware error creation and checking functions.
Package i18nerr provides i18n-aware error creation and checking functions.
libUtils
Package libUtils provides shared utility functions for password encryption, IP lookup, file I/O, and types.
Package libUtils provides shared utility functions for password encryption, IP lookup, file I/O, and types.
liberr
Package liberr provides backward-compatible error checking functions.
Package liberr provides backward-compatible error checking functions.
logutil
Package logutil provides structured logging with debug gate.
Package logutil provides structured logging with debug gate.
uidgen
Package uidgen provides a Snowflake-based unique ID generator.
Package uidgen provides a Snowflake-based unique ID generator.
test
testutil
Package testutil 测试辅助工具
Package testutil 测试辅助工具

Jump to

Keyboard shortcuts

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