初始化
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 80407 (8.4.7)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 15/01/2026 15:27:24
|
||||
Date: 15/01/2026 16:41:33
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -30,6 +30,7 @@ CREATE TABLE `about_profiles` (
|
||||
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '',
|
||||
`wechat` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '',
|
||||
`tech_stack` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT 'JSON string or comma separated list',
|
||||
`experiences` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT 'JSON string of experience list',
|
||||
`is_primary` tinyint(1) NULL DEFAULT 0,
|
||||
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
@@ -39,8 +40,7 @@ CREATE TABLE `about_profiles` (
|
||||
-- ----------------------------
|
||||
-- Records of about_profiles
|
||||
-- ----------------------------
|
||||
INSERT INTO `about_profiles` VALUES (1, '年糕崽崽', 'https://api.dicebear.com/7.x/avataaars/svg?seed=NianGao&backgroundColor=b6e3f4', '中国 · 浙江杭州', '嗨!我是年糕崽崽,一名热衷于探索数字边界的前端架构师。我的职业生涯始于对像素级完美的执念。从早期的 jQuery 插件开发到如今的 WebGL 3D 场景构建,我始终认为:<strong>技术是骨架,艺术是灵魂。</strong><br><br>目前,我专注于高性能 B 端应用的体验升级,以及探索生成式艺术(Generative Art)在网页中的应用。闲暇之余,我喜欢在杭州的西湖边散步,或者捣腾我的客制化机械键盘。', 'hello@niangao.dev', 'Niangao_Dev', '[\"Vue 3\", \"React\", \"TypeScript\", \"Three.js\", \"Golang\", \"Tailwind CSS\", \"Rust\", \"Wails\"]', 1, '2026-01-15 15:22:08', '2026-01-15 15:22:08');
|
||||
INSERT INTO `about_profiles` VALUES (2, '年糕崽崽', 'https://api.dicebear.com/7.x/avataaars/svg?seed=NianGao&backgroundColor=b6e3f4', '中国 · 浙江杭州', '嗨!我是年糕崽崽,一名热衷于探索数字边界的前端架构师。我的职业生涯始于对像素级完美的执念。从早期的 jQuery 插件开发到如今的 WebGL 3D 场景构建,我始终认为:<strong>技术是骨架,艺术是灵魂。</strong><br><br>目前,我专注于高性能 B 端应用的体验升级,以及探索生成式艺术(Generative Art)在网页中的应用。闲暇之余,我喜欢在杭州的西湖边散步,或者捣腾我的客制化机械键盘。', 'hello@niangao.dev', 'Niangao_Dev', '[\"Vue 3\", \"React\", \"TypeScript\", \"Three.js\", \"Golang\", \"Tailwind CSS\", \"Rust\", \"Wails\"]', 1, '2026-01-15 15:24:18', '2026-01-15 15:24:18');
|
||||
INSERT INTO `about_profiles` VALUES (1, '年糕崽崽', 'https://api.dicebear.com/7.x/avataaars/svg?seed=NianGao&backgroundColor=b6e3f4', '中国 · 浙江杭州', '嗨!我是年糕崽崽,一名热衷于探索数字边界的前端架构师。我的职业生涯始于对像素级完美的执念。从早期的 jQuery 插件开发到如今的 WebGL 3D 场景构建,我始终认为:<strong>技术是骨架,艺术是灵魂。</strong><br><br>目前,我专注于高性能 B 端应用的体验升级,以及探索生成式艺术(Generative Art)在网页中的应用。闲暇之余,我喜欢在杭州的西湖边散步,或者捣腾我的客制化机械键盘。', 'hello@niangao.dev', 'Niangao_Dev', '[\"Vue 3\",\"React\",\"TypeScript\",\"Three.js\",\"Golang\",\"Tailwind CSS\",\"Rust\",\"Wails\"]', '[{\"year\":\"2024 - 至今\",\"role\":\"技术负责人\",\"company\":\"某医疗平台公司\"},{\"year\":\"2020 - 2024\",\"role\":\"PHP开发工程师\",\"company\":\"某电商公司\"}]', 1, '2026-01-15 15:22:08', '2026-01-15 15:41:51');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for access_logs
|
||||
@@ -83,7 +83,7 @@ CREATE TABLE `operation_logs` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_user_id`(`user_id` ASC) USING BTREE,
|
||||
INDEX `idx_created_at`(`created_at` ASC) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 88 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '操作日志表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of operation_logs
|
||||
@@ -103,6 +103,78 @@ INSERT INTO `operation_logs` VALUES (12, 1, 'lq', '::1', '/api/admin/dashboard/s
|
||||
INSERT INTO `operation_logs` VALUES (13, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 49, '2026-01-15 13:35:01');
|
||||
INSERT INTO `operation_logs` VALUES (14, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 54, '2026-01-15 13:37:17');
|
||||
INSERT INTO `operation_logs` VALUES (15, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 51, '2026-01-15 13:37:17');
|
||||
INSERT INTO `operation_logs` VALUES (16, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 59, '2026-01-15 15:28:19');
|
||||
INSERT INTO `operation_logs` VALUES (17, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 50, '2026-01-15 15:28:19');
|
||||
INSERT INTO `operation_logs` VALUES (18, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 47, '2026-01-15 15:28:20');
|
||||
INSERT INTO `operation_logs` VALUES (19, 1, 'lq', '::1', '/api/admin/users/2', 'GET', '', 200, 48, '2026-01-15 15:28:22');
|
||||
INSERT INTO `operation_logs` VALUES (20, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 49, '2026-01-15 15:28:23');
|
||||
INSERT INTO `operation_logs` VALUES (21, 1, 'lq', '::1', '/api/admin/users', 'POST', '{\"username\":\"cs\",\"email\":\"cs@nailaoyun.cn\",\"role\":\"viewer\",\"isActive\":1}', 200, 101, '2026-01-15 15:28:35');
|
||||
INSERT INTO `operation_logs` VALUES (22, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 49, '2026-01-15 15:28:35');
|
||||
INSERT INTO `operation_logs` VALUES (23, 1, 'lq', '::1', '/api/admin/users/2', 'GET', '', 200, 46, '2026-01-15 15:28:40');
|
||||
INSERT INTO `operation_logs` VALUES (24, 1, 'lq', '::1', '/api/admin/users/2', 'PUT', '{\"username\":\"editor\",\"email\":\"editor@example.com\",\"role\":\"viewer\",\"isActive\":1}', 200, 97, '2026-01-15 15:28:44');
|
||||
INSERT INTO `operation_logs` VALUES (25, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 45, '2026-01-15 15:28:44');
|
||||
INSERT INTO `operation_logs` VALUES (26, 1, 'lq', '::1', '/api/admin/users/2', 'GET', '', 200, 46, '2026-01-15 15:28:47');
|
||||
INSERT INTO `operation_logs` VALUES (27, 1, 'lq', '::1', '/api/admin/users/2', 'PUT', '{\"username\":\"editor\",\"email\":\"editor@example.com\",\"role\":\"editor\",\"isActive\":1}', 200, 98, '2026-01-15 15:28:49');
|
||||
INSERT INTO `operation_logs` VALUES (28, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 45, '2026-01-15 15:28:49');
|
||||
INSERT INTO `operation_logs` VALUES (29, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 132, '2026-01-15 15:28:50');
|
||||
INSERT INTO `operation_logs` VALUES (30, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 46, '2026-01-15 15:28:51');
|
||||
INSERT INTO `operation_logs` VALUES (31, 1, 'lq', '::1', '/api/admin/works', 'GET', '', 200, 237, '2026-01-15 15:28:52');
|
||||
INSERT INTO `operation_logs` VALUES (32, 1, 'lq', '::1', '/api/admin/snippets', 'GET', '', 200, 45, '2026-01-15 15:28:53');
|
||||
INSERT INTO `operation_logs` VALUES (33, 1, 'lq', '::1', '/api/admin/settings', 'GET', '', 200, 47, '2026-01-15 15:28:54');
|
||||
INSERT INTO `operation_logs` VALUES (34, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 49, '2026-01-15 15:28:54');
|
||||
INSERT INTO `operation_logs` VALUES (35, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 48, '2026-01-15 15:28:55');
|
||||
INSERT INTO `operation_logs` VALUES (36, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 50, '2026-01-15 15:28:55');
|
||||
INSERT INTO `operation_logs` VALUES (37, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 47, '2026-01-15 15:28:55');
|
||||
INSERT INTO `operation_logs` VALUES (38, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 55, '2026-01-15 15:35:04');
|
||||
INSERT INTO `operation_logs` VALUES (39, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 54, '2026-01-15 15:35:04');
|
||||
INSERT INTO `operation_logs` VALUES (40, 1, 'lq', '::1', '/api/admin/works', 'GET', '', 200, 241, '2026-01-15 15:35:07');
|
||||
INSERT INTO `operation_logs` VALUES (41, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 44, '2026-01-15 15:35:08');
|
||||
INSERT INTO `operation_logs` VALUES (42, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 145, '2026-01-15 15:35:09');
|
||||
INSERT INTO `operation_logs` VALUES (43, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 47, '2026-01-15 15:35:09');
|
||||
INSERT INTO `operation_logs` VALUES (44, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 47, '2026-01-15 15:35:12');
|
||||
INSERT INTO `operation_logs` VALUES (45, 1, 'lq', '::1', '/api/admin/settings', 'GET', '', 200, 47, '2026-01-15 15:35:14');
|
||||
INSERT INTO `operation_logs` VALUES (46, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 46, '2026-01-15 15:35:24');
|
||||
INSERT INTO `operation_logs` VALUES (47, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 44, '2026-01-15 15:35:26');
|
||||
INSERT INTO `operation_logs` VALUES (48, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 44, '2026-01-15 15:35:27');
|
||||
INSERT INTO `operation_logs` VALUES (49, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 143, '2026-01-15 15:36:36');
|
||||
INSERT INTO `operation_logs` VALUES (50, 1, 'lq', '::1', '/api/admin/about', 'GET', '', 200, 49, '2026-01-15 15:40:41');
|
||||
INSERT INTO `operation_logs` VALUES (51, 1, 'lq', '::1', '/api/admin/about/2', 'DELETE', '', 200, 42, '2026-01-15 15:40:47');
|
||||
INSERT INTO `operation_logs` VALUES (52, 1, 'lq', '::1', '/api/admin/about', 'GET', '', 200, 42, '2026-01-15 15:40:47');
|
||||
INSERT INTO `operation_logs` VALUES (53, 1, 'lq', '::1', '/api/admin/about', 'GET', '', 200, 40, '2026-01-15 15:40:48');
|
||||
INSERT INTO `operation_logs` VALUES (54, 1, 'lq', '::1', '/api/admin/about/1', 'PUT', '{\"name\":\"年糕崽崽\",\"avatar\":\"https://api.dicebear.com/7.x/avataaars/svg?seed=NianGao&backgroundColor=b6e3f4\",\"location\":\"中国 · 浙江杭州\",\"bio\":\"嗨!我是年糕崽崽,一名热衷于探索数字边界的前端架构师。我的职业生涯始于对像素级完美的执念。从早期的 jQuery 插件开发到如今的 WebGL 3D 场景构建,我始终认为:<strong>技术是骨架,艺术是灵魂。</strong><br><br>目前,我专注于高性能 B 端应用的体验升级,以及探索生成式艺术(Generative Art)在网页中的应用。闲暇之余,我喜欢在杭州的西湖边散步,或者捣腾我的客制化机械键盘。\",\"email\":\"hello@niangao.dev\",\"wechat\":\"Niangao_Dev\",\"isPrimary\":true,\"experiences\":[{\"year\":\"2024 - 至今\",\"role\":\"技术负责人\",\"company\":\"某医疗平台公司\"},{\"year\":\"2020 - 2024\",\"role\":\"PHP开发工程师\",\"company\":\"某电商公司\"}],\"techStack\":[\"Vue 3\",\"React\",\"TypeScript\",\"Three.js\",\"Golang\",\"Tailwind CSS\",\"Rust\",\"Wails\"]}', 200, 55, '2026-01-15 15:41:51');
|
||||
INSERT INTO `operation_logs` VALUES (55, 1, 'lq', '::1', '/api/admin/about', 'GET', '', 200, 47, '2026-01-15 15:41:51');
|
||||
INSERT INTO `operation_logs` VALUES (56, 1, 'lq', '::1', '/api/admin/tags', 'GET', '', 200, 45, '2026-01-15 15:41:59');
|
||||
INSERT INTO `operation_logs` VALUES (57, 1, 'lq', '::1', '/api/admin/works', 'GET', '', 200, 221, '2026-01-15 15:41:59');
|
||||
INSERT INTO `operation_logs` VALUES (58, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 45, '2026-01-15 15:42:01');
|
||||
INSERT INTO `operation_logs` VALUES (59, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 131, '2026-01-15 15:42:02');
|
||||
INSERT INTO `operation_logs` VALUES (60, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 44, '2026-01-15 15:42:03');
|
||||
INSERT INTO `operation_logs` VALUES (61, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 42, '2026-01-15 15:42:04');
|
||||
INSERT INTO `operation_logs` VALUES (62, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 49, '2026-01-15 15:42:04');
|
||||
INSERT INTO `operation_logs` VALUES (63, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 42, '2026-01-15 15:42:07');
|
||||
INSERT INTO `operation_logs` VALUES (64, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 49, '2026-01-15 16:15:53');
|
||||
INSERT INTO `operation_logs` VALUES (65, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 51, '2026-01-15 16:15:53');
|
||||
INSERT INTO `operation_logs` VALUES (66, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 47, '2026-01-15 16:15:56');
|
||||
INSERT INTO `operation_logs` VALUES (67, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 51, '2026-01-15 16:16:31');
|
||||
INSERT INTO `operation_logs` VALUES (68, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 49, '2026-01-15 16:16:31');
|
||||
INSERT INTO `operation_logs` VALUES (69, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 49, '2026-01-15 16:16:33');
|
||||
INSERT INTO `operation_logs` VALUES (70, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 145, '2026-01-15 16:16:33');
|
||||
INSERT INTO `operation_logs` VALUES (71, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 48, '2026-01-15 16:16:34');
|
||||
INSERT INTO `operation_logs` VALUES (72, 1, 'lq', '::1', '/api/admin/works', 'GET', '', 200, 239, '2026-01-15 16:16:35');
|
||||
INSERT INTO `operation_logs` VALUES (73, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 48, '2026-01-15 16:16:36');
|
||||
INSERT INTO `operation_logs` VALUES (74, 1, 'lq', '::1', '/api/admin/tags', 'GET', '', 200, 51, '2026-01-15 16:16:36');
|
||||
INSERT INTO `operation_logs` VALUES (75, 1, 'lq', '::1', '/api/admin/about', 'GET', '', 200, 47, '2026-01-15 16:16:37');
|
||||
INSERT INTO `operation_logs` VALUES (76, 1, 'lq', '::1', '/api/admin/settings', 'GET', '', 200, 50, '2026-01-15 16:16:37');
|
||||
INSERT INTO `operation_logs` VALUES (77, 1, 'lq', '::1', '/api/admin/operation-logs', 'GET', '', 200, 47, '2026-01-15 16:16:38');
|
||||
INSERT INTO `operation_logs` VALUES (78, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 49, '2026-01-15 16:16:38');
|
||||
INSERT INTO `operation_logs` VALUES (79, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 48, '2026-01-15 16:16:39');
|
||||
INSERT INTO `operation_logs` VALUES (80, 1, 'lq', '::1', '/api/admin/dashboard/stats', 'GET', '', 200, 49, '2026-01-15 16:18:36');
|
||||
INSERT INTO `operation_logs` VALUES (81, 1, 'lq', '::1', '/api/admin/dashboard/activities', 'GET', '', 200, 54, '2026-01-15 16:18:36');
|
||||
INSERT INTO `operation_logs` VALUES (82, 1, 'lq', '::1', '/api/admin/snippets', 'GET', '', 200, 47, '2026-01-15 16:18:40');
|
||||
INSERT INTO `operation_logs` VALUES (83, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 52, '2026-01-15 16:19:16');
|
||||
INSERT INTO `operation_logs` VALUES (84, 1, 'lq', '::1', '/api/admin/roles', 'GET', '', 200, 145, '2026-01-15 16:19:17');
|
||||
INSERT INTO `operation_logs` VALUES (85, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 46, '2026-01-15 16:19:17');
|
||||
INSERT INTO `operation_logs` VALUES (86, 1, 'lq', '::1', '/api/admin/users', 'GET', '', 200, 49, '2026-01-15 16:32:17');
|
||||
INSERT INTO `operation_logs` VALUES (87, 1, 'lq', '::1', '/api/admin/posts', 'GET', '', 200, 47, '2026-01-15 16:32:18');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for permissions
|
||||
@@ -197,7 +269,10 @@ CREATE TABLE `posts` (
|
||||
-- ----------------------------
|
||||
-- Records of posts
|
||||
-- ----------------------------
|
||||
INSERT INTO `posts` VALUES ('refactor', '重构的艺术:如何优雅地处理遗留代码', '工程化', '2026-01-12', '在本文中,我们将探讨重构的核心原则和实用技巧,帮助你优雅地处理遗留代码,提高代码质量和可维护性。', '<h2>什么是代码重构?</h2><p>代码重构是在不改变代码外部行为的前提下,优化代码内部结构的过程...</p>', 1, 1, '2026-01-13 16:10:14', '2026-01-15 15:01:35');
|
||||
INSERT INTO `posts` VALUES ('goravel-guide-1', 'Goravel 入门指南 (一):环境搭建与 Hello World', 'Go语言', '2025-10-25', '本文将带你了解 Go 语言领域的 Laravel —— Goravel 框架,并演示如何快速搭建环境及运行第一个 Web 服务。', '## 什么是 Goravel?\n\nGoravel 是一个基于 Go 语言的 Web 开发框架,它的设计理念深受 PHP Laravel 框架的启发。如果你是一名从 PHP 转 Go 的开发者,或者你喜欢 Laravel 那种“开箱即用、优雅简洁”的开发体验,那么 Goravel 绝对是你的不二之选。\n\n它集成了丰富的功能模块,包括但不限于:\n- 强大的路由系统\n- ORM(基于 GORM 封装)\n- 依赖注入容器\n- 队列与任务调度\n- 缓存与文件存储\n\n## 环境搭建\n\nGoravel 提供了一个名为 `knit` 的命令行工具(类似 Laravel 的 artisan),可以帮助我们快速初始化项目。\n\n### 1. 安装 Knit CLI\n\n确保你已经安装了 Go (1.20+),然后运行以下命令:\n\n```bash\ngo install github.com/goravel/knit/cmd/knit@latest\n```\n\n### 2. 创建新项目\n\n使用 `knit new` 命令创建项目:\n\n```bash\nknit new my-goravel-app\ncd my-goravel-app\n```\n\n### 3. 安装依赖\n\n```bash\ngo mod tidy\n```\n\n## 目录结构\n\n打开项目,你会发现它的目录结构非常清晰,带有浓厚的 Laravel 风格:\n\n- **app/**: 核心业务代码(Http 控制器、模型、服务提供者等)\n- **config/**: 配置文件(应用配置、数据库配置等)\n- **routes/**: 路由定义文件\n- **database/**: 数据库迁移与填充\n- **public/**: 静态资源文件\n\n## 运行 Hello World\n\nGoravel 的入口文件是根目录下的 `main.go`。在运行之前,我们先看一眼路由定义。打开 `routes/web.go`:\n\n```go\npackage routes\n\nimport (\n \"github.com/goravel/framework/contracts/http\"\n \"github.com/goravel/framework/facades\"\n)\n\nfunc Web() {\n facades.Route().Get(\"/\", func(ctx http.Context) http.Response {\n return ctx.Response().Json(200, http.Json{\n \"Hello\": \"Goravel\",\n })\n })\n}\n```\n\n非常直观!现在让我们启动服务:\n\n```bash\ngo run .\n```\n\n默认情况下,服务会运行在 `http://localhost:3000`。打开浏览器访问,你应该能看到 JSON 响应:\n\n```json\n{\n \"Hello\": \"Goravel\"\n}\n```\n\n至此,你已经成功运行了你的第一个 Goravel 应用!在下一篇文章中,我们将深入探讨路由与控制器的使用。', 1206, 1, '2026-01-15 16:32:12', '2026-01-15 16:32:27');
|
||||
INSERT INTO `posts` VALUES ('goravel-guide-2', 'Goravel 入门指南 (二):路由与控制器', 'Go语言', '2025-10-26', '深入理解 Goravel 的 HTTP 层,学习如何定义 RESTful 路由、创建控制器以及处理 HTTP 请求与响应。', '## 路由系统\n\n在 Goravel 中,路由定义通常位于 `routes/` 目录下。`api.go` 用于定义 API 路由,`web.go` 用于定义网页路由。Goravel 使用 `facades.Route()` 来定义路由,这得益于其强大的依赖注入系统。\n\n### 基础路由\n\n```go\n// GET 请求\nfacades.Route().Get(\"/users\", func(ctx http.Context) http.Response {\n return ctx.Response().String(200, \"User List\")\n})\n\n// POST 请求\nfacades.Route().Post(\"/users\", func(ctx http.Context) http.Response {\n return ctx.Response().Success().Json(http.Json{\"id\": 1})\n})\n```\n\n### 路由参数\n\n获取 URL 中的动态参数非常简单:\n\n```go\nfacades.Route().Get(\"/users/{id}\", func(ctx http.Context) http.Response {\n id := ctx.Request().Input(\"id\")\n return ctx.Response().Success().Json(http.Json{\"user_id\": id})\n})\n```\n\n## 控制器 (Controllers)\n\n随着应用变大,我们不可能把所有逻辑都写在路由闭包里。这时候就需要控制器了。\n\n### 创建控制器\n\n使用 `knit` 工具可以快速生成控制器:\n\n```bash\nknit make:controller UserController\n```\n\n这会在 `app/http/controllers` 目录下生成 `user_controller.go`。让我们修改它来添加一个 `Show` 方法:\n\n```go\npackage controllers\n\nimport (\n \"github.com/goravel/framework/contracts/http\"\n)\n\ntype UserController struct {\n // 可以在这里注入服务\n}\n\nfunc NewUserController() *UserController {\n return &UserController{}\n}\n\nfunc (r *UserController) Show(ctx http.Context) http.Response {\n id := ctx.Request().Input(\"id\")\n // 模拟数据库查询\n return ctx.Response().Success().Json(http.Json{\n \"id\": id,\n \"name\": \"Goravel User\",\n })\n}\n```\n\n### 注册控制器路由\n\n回到 `routes/api.go`,我们需要先实例化控制器,然后绑定路由:\n\n```go\nimport \"my-goravel-app/app/http/controllers\"\n\nfunc Api() {\n userController := controllers.NewUserController()\n \n // 绑定到控制器方法\n facades.Route().Get(\"/users/{id}\", userController.Show)\n}\n```\n\n## 请求与响应\n\n在控制器方法中,`ctx` (http.Context) 是核心:\n\n- **获取输入**: `ctx.Request().Input(\"key\")`\n- **获取 JSON**: `ctx.Request().Bind(&user)`\n- **返回 JSON**: `ctx.Response().Json(200, data)`\n- **设置状态码**: `ctx.Response().Status(404)`\n\n通过这种方式,Goravel 让 HTTP 层的处理变得异常清晰和标准化。下一章,我们将学习如何通过 ORM 操作数据库。', 894, 1, '2026-01-15 16:32:12', '2026-01-15 16:40:58');
|
||||
INSERT INTO `posts` VALUES ('goravel-guide-3', 'Goravel 入门指南 (三):ORM 数据库操作', 'Go语言', '2025-10-27', '掌握 Goravel 强大的 ORM 功能,从数据库配置、模型定义到执行增删改查(CRUD)操作。', '## Goravel ORM 简介\n\nGoravel 的 ORM 基于著名的 GORM 库构建,但它进行了一层优雅的封装,使其调用方式更接近 Laravel 的 Eloquent ORM。这意味着你可以使用 Facade 模式轻松调用数据库,且支持自动迁移。\n\n## 配置数据库\n\n打开 `config/database.go` 或 `.env` 文件,配置你的 MySQL 连接信息:\n\n```env\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=goravel\nDB_USERNAME=root\nDB_PASSWORD=password\n```\n\n## 定义模型\n\n使用 `knit` 生成模型:\n\n```bash\nknit make:model Post\n```\n\n生成的模型文件位于 `app/models/post.go`。我们需要定义结构体字段:\n\n```go\npackage models\n\nimport (\n \"github.com/goravel/framework/database/orm\"\n)\n\ntype Post struct {\n orm.Model\n Title string `gorm:\"size:255;not null\"`\n Content string `gorm:\"type:text\"`\n UserID uint\n}\n```\n\n## 数据库迁移\n\n虽然 GORM 支持 AutoMigrate,但 Goravel 推荐使用迁移文件来管理数据库变更。\n\n```bash\nknit make:migration create_posts_table\n```\n\n编辑生成的迁移文件 (`database/migrations/xxxx_create_posts_table.go`),定义表结构,然后运行:\n\n```bash\nknit migrate\n```\n\n## CRUD 操作\n\n有了模型,我们就可以愉快地操作数据库了。所有操作都通过 `facades.Orm()` 入口。\n\n### 创建 (Create)\n\n```go\npost := models.Post{\n Title: \"My First Post\",\n Content: \"Content goes here...\",\n}\nerr := facades.Orm().Query().Create(&post)\n```\n\n### 查询 (Read)\n\n```go\nvar post models.Post\n// 根据主键查询\nfacades.Orm().Query().Find(&post, 1)\n\n// 条件查询\nvar posts []models.Post\nfacades.Orm().Query().Where(\"title\", \"My First Post\").Get(&posts)\n```\n\n### 更新 (Update)\n\n```go\nvar post models.Post\nfacades.Orm().Query().Find(&post, 1)\n\npost.Title = \"Updated Title\"\nfacades.Orm().Query().Save(&post)\n```\n\n### 删除 (Delete)\n\n```go\nvar post models.Post\nfacades.Orm().Query().Delete(&post, 1)\n```\n\nGoravel 的 ORM 让 Go 语言的数据库操作不再繁琐,极大地提高了开发效率。配合之前的路由和控制器知识,你现在已经具备了开发完整 RESTful API 的能力!', 1560, 1, '2026-01-15 16:32:12', '2026-01-15 16:32:12');
|
||||
INSERT INTO `posts` VALUES ('refactor', '重构的艺术:如何优雅地处理遗留代码', '工程化', '2026-01-12', '在本文中,我们将探讨重构的核心原则和实用技巧,帮助你优雅地处理遗留代码,提高代码质量和可维护性。', '<h2>什么是代码重构?</h2><p>代码重构是在不改变代码外部行为的前提下,优化代码内部结构的过程...</p>', 3, 1, '2026-01-13 16:10:14', '2026-01-15 16:16:57');
|
||||
INSERT INTO `posts` VALUES ('shader', '着色器魔法:从零开始写一个噪声生成器', '图形渲染', '2025-12-08', '深入了解WebGL着色器,学习如何从零开始实现一个高性能的噪声生成器,为你的3D作品增添独特的视觉效果。', ' <p>GLSL (OpenGL Shading Language) 是一门让人生畏但也充满魅力的语言。它运行在 GPU 上,能够并行处理数百万个像素,创造出惊人的视觉效果。</p>\r\n <h2>什么是柏林噪声?</h2>\r\n <p>柏林噪声(Perlin Noise)是一种梯度噪声,它比普通的随机数生成的噪声看起来更自然、更平滑。它常被用来模拟云彩、地形、火焰等自然现象。</p>\r\n <h2>Three.js 中的实现</h2>\r\n <p>在 Three.js 中,我们可以通过 <code>ShaderMaterial</code> 直接编写 GLSL 代码。</p>\r\n <pre><code><span class=\"code-comment\">// 简单的顶点着色器</span>\r\n<span class=\"code-keyword\">varying</span> <span class=\"code-keyword\">vec2</span> vUv;\r\n<span class=\"code-keyword\">void</span> <span class=\"code-func\">main</span>() {\r\n vUv = uv;\r\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\r\n}</code></pre>\r\n <p>通过调整噪声的频率和振幅,我们可以得到各种不同的纹理效果。在我的个人网站背景中,就使用了这种技术来生成流动的极光效果。</p>\r\n ', 1, 1, '2026-01-13 16:10:14', '2026-01-15 15:03:42');
|
||||
INSERT INTO `posts` VALUES ('ux', '用户体验设计:从认知心理学到交互实践', '设计思维', '2025-11-20', '探索用户体验设计的核心原理,结合认知心理学知识,学习如何设计出真正符合用户需求的交互界面。', '<h2>认知心理学在UX设计中的应用</h2><p>了解用户的认知过程是设计良好用户体验的基础...</p>', 0, 1, '2026-01-13 16:10:14', '2026-01-13 16:10:14');
|
||||
|
||||
@@ -374,13 +449,14 @@ CREATE TABLE `users` (
|
||||
INDEX `idx_role`(`role` ASC) USING BTREE COMMENT '按角色查询索引',
|
||||
INDEX `users_ibfk_1`(`role_id` ASC) USING BTREE,
|
||||
CONSTRAINT `users_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of users
|
||||
-- ----------------------------
|
||||
INSERT INTO `users` VALUES (1, 'lq', 'liqiworker@gmail.com', '$2a$10$yl.1yCZ2PSTsW14byyDQ3uekuEiqnC4VBr/TzR6OvMqFVRuiiHu5e', 1, 'admin', 1, '2026-01-13 16:10:14', '2026-01-15 13:22:46');
|
||||
INSERT INTO `users` VALUES (2, 'editor', 'editor@example.com', '$2a$10$J9q3NfJ2X8H7Q5z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q', 2, 'editor', 1, '2026-01-13 16:10:14', '2026-01-13 16:10:14');
|
||||
INSERT INTO `users` VALUES (2, 'editor', 'editor@example.com', '$2a$10$J9q3NfJ2X8H7Q5z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q7z5Q', 2, 'editor', 1, '2026-01-13 16:10:14', '2026-01-15 15:28:49');
|
||||
INSERT INTO `users` VALUES (5, 'cs', 'cs@nailaoyun.cn', '$2a$10$5hmE0v3NZRTRZddfIH4kpOT0XAuWtX8Zp86zBl0RcH6RkH6jP01ku', 3, 'viewer', 1, '2026-01-15 15:28:35', '2026-01-15 15:28:35');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for work_gallery
|
||||
|
||||
Reference in New Issue
Block a user