-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f64350
commit 9c23f23
Showing
9 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# db tmp data | ||
storage/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# configs:配置文件。 | ||
# docs:文档集合。 | ||
# global:全局变量。 | ||
# internal:内部模块。 | ||
# dao:数据访问层(Database Access Object),所有与数据相关的操作都会在 dao 层进行,例如 MySQL、ElasticSearch 等。 | ||
# middleware:HTTP 中间件。 | ||
# model:模型层,用于存放 model 对象。 | ||
# routers:路由相关逻辑处理。 | ||
# service:项目核心业务逻辑。 | ||
# pkg:项目相关的模块包。 | ||
# storage:项目生成的临时文件。 | ||
# scripts:各类构建,安装,分析等操作的脚本。 | ||
# third_party:第三方的资源工具,例如 Swagger UI。 | ||
|
||
mkdir {configs,docs,global,internal,pkg,storage,scripts,third_party} | ||
mkdir internal/{dao,middleware,model,routers,service} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: '3.7' | ||
services: | ||
blog_service: | ||
image: mysql:5.7 | ||
ports: | ||
- 3306:3306 | ||
command: --init-file /data/application/init.sql | ||
volumes: | ||
- ./storage/dbdata:/var/lib/mysql | ||
- ./scripts/init.sql:/data/application/init.sql | ||
container_name: blog_service | ||
environment: | ||
- PUID=1000 | ||
- PGID=1000 | ||
- MYSQL_ROOT_PASSWORD=root | ||
- TZ=Asia/Shanghai | ||
- MYSQL_DATABASE=blog_service | ||
- MYSQL_USER=blog_service | ||
- MYSQL_PASSWORD=blog_service | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package model | ||
|
||
type Article struct { | ||
*Model | ||
Title string `json:"title"` | ||
Desc string `json:"desc"` | ||
Content string `json:"content"` | ||
CoverImageUrl string `json:"cover_image_url"` | ||
State uint8 `json:"state"` | ||
} | ||
|
||
func (a Article) TableName() string { | ||
return "blog_article" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package model | ||
|
||
type ArticleTag struct { | ||
*Model | ||
TagID uint32 `json:"tag_id"` | ||
ArticleID uint32 `json:"article_id"` | ||
} | ||
|
||
func (a ArticleTag) TableName() string { | ||
return "blog_article_tag" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package model | ||
|
||
// Model 作为公共部分字段被其他model引入 | ||
type Model struct { | ||
ID uint32 `gorm:"primary_key" json:"id"` | ||
CreatedBy string `json:"created_by"` | ||
ModifiedBy string `json:"modified_by"` | ||
CreatedOn uint32 `json:"created_on"` | ||
ModifiedOn uint32 `json:"modified_on"` | ||
DeletedOn uint32 `json:"deleted_on"` | ||
IsDel uint8 `json:"is_del"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package model | ||
|
||
type Tag struct { | ||
*Model | ||
Name string `json:"name"` | ||
State uint8 `json:"state"` | ||
} | ||
|
||
func (t Tag) TableName() string { | ||
return "blog_tag" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
CREATE | ||
DATABASE | ||
IF | ||
NOT EXISTS blog_service DEFAULT CHARACTER | ||
SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci; | ||
|
||
use blog_service; | ||
-- 创建标签表 | ||
CREATE TABLE IF NOT EXISTS `blog_tag` | ||
( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`name` varchar(100) DEFAULT '' COMMENT '标签名称', | ||
`created_on` int(10) unsigned DEFAULT '0' COMMENT '创建时间', | ||
`created_by` varchar(100) DEFAULT '' COMMENT '创建人', | ||
`modified_on` int(10) unsigned DEFAULT '0' COMMENT '修改时间', | ||
`modified_by` varchar(100) DEFAULT '' COMMENT '修改人', | ||
`deleted_on` int(10) unsigned DEFAULT '0' COMMENT '删除时间', | ||
`is_del` tinyint(3) unsigned DEFAULT '0' COMMENT '是否删除 0 为未删除、1 为已删除', | ||
`state` tinyint(3) unsigned DEFAULT '1' COMMENT '状态 0 为禁用、1 为启用', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='标签管理'; | ||
|
||
-- 创建文章表 | ||
CREATE TABLE IF NOT EXISTS `blog_article` | ||
( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`title` varchar(100) DEFAULT '' COMMENT '文章标题', | ||
`desc` varchar(255) DEFAULT '' COMMENT '文章简述', | ||
`cover_image_url` varchar(255) DEFAULT '' COMMENT '封面图片地址', | ||
`content` longtext COMMENT '文章内容', | ||
`created_on` int(10) unsigned DEFAULT '0' COMMENT '创建时间', | ||
`created_by` varchar(100) DEFAULT '' COMMENT '创建人', | ||
`modified_on` int(10) unsigned DEFAULT '0' COMMENT '修改时间', | ||
`modified_by` varchar(100) DEFAULT '' COMMENT '修改人', | ||
`deleted_on` int(10) unsigned DEFAULT '0' COMMENT '删除时间', | ||
`is_del` tinyint(3) unsigned DEFAULT '0' COMMENT '是否删除 0 为未删除、1 为已删除', | ||
`state` tinyint(3) unsigned DEFAULT '1' COMMENT '状态 0 为禁用、1 为启用', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章管理'; | ||
|
||
-- 创建文章标签关联表 | ||
CREATE TABLE IF NOT EXISTS `blog_article_tag` | ||
( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`article_id` int(11) NOT NULL COMMENT '文章 ID', | ||
`tag_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '标签 ID', | ||
`created_on` int(10) unsigned DEFAULT '0' COMMENT '创建时间', | ||
`created_by` varchar(100) DEFAULT '' COMMENT '创建人', | ||
`modified_on` int(10) unsigned DEFAULT '0' COMMENT '修改时间', | ||
`modified_by` varchar(100) DEFAULT '' COMMENT '修改人', | ||
`deleted_on` int(10) unsigned DEFAULT '0' COMMENT '删除时间', | ||
`is_del` tinyint(3) unsigned DEFAULT '0' COMMENT '是否删除 0 为未删除、1 为已删除', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章标签关联'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker-compose up -d |